diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 6e1d9e8fef5e4da6f277bf2302544ef4994e3efc..d7a3056932d2e4a98212b2fbeb6bd1d4a2d2faf4 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":