diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 71955e300ed2751bd2838718c9d310d90027a1c7..39d9e38d5c9d0d943af83e075a3923de2b0d7bd7 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -3687,6 +3687,7 @@ class Query(): self.flags = dict() self.messages = _Messages() self.cached = None + self.etag = None if isinstance(q, etree._Element): self.q = q.get("string") @@ -3696,6 +3697,7 @@ class Query(): self.cached = False else: self.cached = q.get("cached").lower() == "true" + self.etag = q.get("etag") for m in q: if m.tag.lower() == 'warning' or m.tag.lower() == 'error': @@ -3740,6 +3742,7 @@ class Query(): cresp = Container._response_to_entities(http_response) self.results = cresp.query.results self.cached = cresp.query.cached + self.etag = cresp.query.etag if self.q.lower().startswith('count') and len(cresp) == 0: # this was a count query diff --git a/unittests/test_query.py b/unittests/test_query.py index f4b3ee9762d9d76b65ace9a5b9b3f4039c0c6919..12622ea486dda717ca1fbc1255510575c5e0c8e6 100644 --- a/unittests/test_query.py +++ b/unittests/test_query.py @@ -26,20 +26,23 @@ import caosdb as db def test_query_parsing(): - s = '<Query string="FIND bla" results="0" cached="true"/>' + s = '<Query string="FIND bla" results="0" cached="true" etag="asdf"/>' q = db.Query(etree.fromstring(s)) assert q.q == "FIND bla" assert q.results == 0 assert q.cached is True + assert q.etag == "asdf" - s = '<Query string="COUNT bla" results="1" cached="false"/>' + s = '<Query string="COUNT bla" results="1" cached="false" etag="asdf"/>' q = db.Query(etree.fromstring(s)) assert q.q == "COUNT bla" assert q.results == 1 assert q.cached is False + assert q.etag == "asdf" s = '<Query string="COUNT blub" results="4"/>' q = db.Query(etree.fromstring(s)) assert q.q == "COUNT blub" assert q.results == 4 assert q.cached is False + assert q.etag is None