Skip to content
Snippets Groups Projects
Verified Commit 1ff14940 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'f-etag' into f-fsm

parents 2c003e18 18c3632c
No related branches found
No related tags found
1 merge request!3F fsm
......@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Entity State support (experimental, no StateModel support yet). See the `caosdb.State` class for
more information.
* `etag` property for the `caosdb.Query` class. The etag allows to debug the
caching and to decide whether the server has changed between queries.
### Changed ###
......
......@@ -3671,6 +3671,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")
......@@ -3680,6 +3681,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':
......@@ -3724,6 +3726,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
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment