From df73889d12667f4a5a7c2ae952aab8e6f9d475fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Fri, 12 Feb 2021 15:17:36 +0000 Subject: [PATCH] F fix 43 --- CHANGELOG.md | 2 ++ src/caosdb/common/models.py | 6 ++++- unittests/test_query.py | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 unittests/test_query.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b35d194..e4479048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### +* #43 - Error with `execute_query` when server doesn't support query caching. + ### Security ### ## [0.5.0] - 2021-02-11 ## diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 28911443..9592e484 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -3665,7 +3665,11 @@ class Query(): if isinstance(q, etree._Element): self.q = q.get("string") self.results = int(q.get("results")) - self.cached = q.get("cached").lower() == "true" + + if q.get("cached") is None: + self.cached = False + else: + self.cached = q.get("cached").lower() == "true" for m in q: if m.tag.lower() == 'warning' or m.tag.lower() == 'error': diff --git a/unittests/test_query.py b/unittests/test_query.py new file mode 100644 index 00000000..f4b3ee97 --- /dev/null +++ b/unittests/test_query.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +# +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2021 Indiscale GmbH <info@indiscale.com> +# Copyright (C) 2021 Timm Fitschen <f.fitschen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +# ** end header +# +from lxml import etree +import caosdb as db + + +def test_query_parsing(): + s = '<Query string="FIND bla" results="0" cached="true"/>' + q = db.Query(etree.fromstring(s)) + assert q.q == "FIND bla" + assert q.results == 0 + assert q.cached is True + + s = '<Query string="COUNT bla" results="1" cached="false"/>' + q = db.Query(etree.fromstring(s)) + assert q.q == "COUNT bla" + assert q.results == 1 + assert q.cached is False + + 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 -- GitLab