From 7780e9ec1373deddc4937265b060ab5830b9624e Mon Sep 17 00:00:00 2001
From: Daniel Hornung <d.hornung@indiscale.com>
Date: Sun, 14 Apr 2024 10:20:09 +0200
Subject: [PATCH] FIX, MAINT: Two small changes.

---
 src/linkahead/common/models.py | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py
index 6e1d9e8f..d7a30569 100644
--- a/src/linkahead/common/models.py
+++ b/src/linkahead/common/models.py
@@ -4655,8 +4655,8 @@ class Query():
 
     Attributes
     ----------
-    q : str
-        The query string.
+    q : str, etree._Element
+        The query string, may also be a query XML snippet.
     flags : dict of str
         A dictionary of flags to be send with the query request.
     messages : Messages()
@@ -4687,13 +4687,11 @@ class Query():
         self.etag = None
 
         if isinstance(q, etree._Element):
-            string = q.get("string")
-            self.q = string if string is not None else ""
+            q.get("string")
+            self.q = q.get("string", "")
             results = q.get("results")
             if results is None:
-                raise LinkAheadException(
-                    "The query result count is not available in the response."
-                )
+                raise LinkAheadException("The query result count is not available in the response.")
             self.results = int(results)
 
             cached_value = q.get("cached")
@@ -5096,9 +5094,9 @@ def _parse_single_xml_element(elem: etree._Element):
         return Message(type='History', description=elem.get("transaction"))
     elif elem.tag.lower() == 'stats':
         counts = elem.find("counts")
-        if counts is not None:
-            attrib: Union[str, etree._Attrib] = counts.attrib
-        return Message(type="Counts", description=None, body=attrib)
+        if counts is None:
+            raise LinkAheadException("'stats' element without a 'count' found.")
+        return Message(type="Counts", description=None, body=counts.attrib)
     elif elem.tag == "EntityACL":
         return ACL(xml=elem)
     elif elem.tag == "Permissions":
-- 
GitLab