From 9fe1019d508619fc08ff6bd17c3adfc600250a8a Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Wed, 21 Jun 2023 09:26:12 +0200
Subject: [PATCH] TEST: New test for server-issue 220.

See https://gitlab.com/caosdb/caosdb-server/-/issues/220
---
 tests/test_issues_server.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tests/test_issues_server.py b/tests/test_issues_server.py
index a26d53a..0ad2839 100644
--- a/tests/test_issues_server.py
+++ b/tests/test_issues_server.py
@@ -1374,3 +1374,33 @@ def test_138():
         # No error, but of course also no results.
         results = db.execute_query(query)
         assert len(results) == 0
+
+
+@pytest.mark.xfail(reason="Needs fix for parent name change caching, "
+                   "see https://gitlab.com/caosdb/caosdb-server/-/issues/220")
+def test_220():
+    """Caching of children is not removed.
+
+See https://gitlab.com/caosdb/caosdb-server/-/issues/220"""
+    rectype = db.RecordType(name="OldName").insert()
+    rec = db.Record(name="rec").add_parent(rectype).insert()
+
+    query = db.Query("FIND rec")
+    assert query.cached is None
+
+    res_1 = query.execute(unique=True)
+    assert query.cached == False, "First query should be uncached."
+    assert res_1.id == rec.id
+
+    res_2 = query.execute(unique=True)
+    assert query.cached == True, "Second query should be cached."
+
+    rectype.name = "NewName"
+    rectype.update()
+
+    res_3 = query.execute(unique=True)
+    assert res_3.parents[0].name == rectype.name, \
+        "The name of the record's parent should be up-to-date."
+    assert query.cached == False, "Query after name change of parent should not be cached."
+
+    r.retrieve(flags={"cache": "false"})
-- 
GitLab