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

Merge branch 'f-fsm' into f-fsm-v0.2

parents 4d9f55b4 1ff14940
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 ...@@ -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 * Entity State support (experimental, no StateModel support yet). See the `caosdb.State` class for
more information. 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 ### ### Changed ###
......
...@@ -3687,6 +3687,7 @@ class Query(): ...@@ -3687,6 +3687,7 @@ class Query():
self.flags = dict() self.flags = dict()
self.messages = _Messages() self.messages = _Messages()
self.cached = None self.cached = None
self.etag = None
if isinstance(q, etree._Element): if isinstance(q, etree._Element):
self.q = q.get("string") self.q = q.get("string")
...@@ -3696,6 +3697,7 @@ class Query(): ...@@ -3696,6 +3697,7 @@ class Query():
self.cached = False self.cached = False
else: else:
self.cached = q.get("cached").lower() == "true" self.cached = q.get("cached").lower() == "true"
self.etag = q.get("etag")
for m in q: for m in q:
if m.tag.lower() == 'warning' or m.tag.lower() == 'error': if m.tag.lower() == 'warning' or m.tag.lower() == 'error':
...@@ -3740,6 +3742,7 @@ class Query(): ...@@ -3740,6 +3742,7 @@ class Query():
cresp = Container._response_to_entities(http_response) cresp = Container._response_to_entities(http_response)
self.results = cresp.query.results self.results = cresp.query.results
self.cached = cresp.query.cached self.cached = cresp.query.cached
self.etag = cresp.query.etag
if self.q.lower().startswith('count') and len(cresp) == 0: if self.q.lower().startswith('count') and len(cresp) == 0:
# this was a count query # this was a count query
......
...@@ -26,20 +26,23 @@ import caosdb as db ...@@ -26,20 +26,23 @@ import caosdb as db
def test_query_parsing(): 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)) q = db.Query(etree.fromstring(s))
assert q.q == "FIND bla" assert q.q == "FIND bla"
assert q.results == 0 assert q.results == 0
assert q.cached is True 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)) q = db.Query(etree.fromstring(s))
assert q.q == "COUNT bla" assert q.q == "COUNT bla"
assert q.results == 1 assert q.results == 1
assert q.cached is False assert q.cached is False
assert q.etag == "asdf"
s = '<Query string="COUNT blub" results="4"/>' s = '<Query string="COUNT blub" results="4"/>'
q = db.Query(etree.fromstring(s)) q = db.Query(etree.fromstring(s))
assert q.q == "COUNT blub" assert q.q == "COUNT blub"
assert q.results == 4 assert q.results == 4
assert q.cached is False 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