Skip to content
Snippets Groups Projects
Commit f16618f9 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-etag' into 'dev'

ENH: etag property for the query

See merge request caosdb/caosdb-pylib!55
parents d4d83650 c66ad4e1
No related branches found
No related tags found
1 merge request!2F doc version
Pipeline #5231 failed
...@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### ### Added ###
* `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 ###
### Deprecated ### ### Deprecated ###
......
...@@ -3661,6 +3661,7 @@ class Query(): ...@@ -3661,6 +3661,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")
...@@ -3670,6 +3671,7 @@ class Query(): ...@@ -3670,6 +3671,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':
...@@ -3714,6 +3716,7 @@ class Query(): ...@@ -3714,6 +3716,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