aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorJohn Nduli2024-09-24 09:45:30 +0300
committerBonfaceKilz2024-09-30 11:14:08 +0300
commitacf133de4cc482ba8c4954179757e301f52c751a (patch)
treec62b56ff60a8e3533b0a64793986382c5e3adbdc /gn3
parenta72bc11be719b4726f05388ff053d52b192c8a50 (diff)
downloadgenenetwork3-acf133de4cc482ba8c4954179757e301f52c751a.tar.gz
fix: rdf and sql queries for fetching rif data
SQL queries fail because we get bytes instead of strings which cannot be decoded. We decode results from DictCursor to fix this. For RDF, we cast `?symbol` to a string.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/db/rdf/wiki.py2
-rw-r--r--gn3/db/wiki.py14
2 files changed, 13 insertions, 3 deletions
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py
index 4464eed..b2b301a 100644
--- a/gn3/db/rdf/wiki.py
+++ b/gn3/db/rdf/wiki.py
@@ -86,7 +86,7 @@ CONSTRUCT {
rdf:type gnc:GNWikiEntry ;
dct:identifier ?id_ ;
dct:created ?createTime .
- FILTER ( LCASE(?symbol) = LCASE('$symbol') ) .
+ FILTER ( LCASE(STR(?symbol)) = LCASE("$symbol") ) .
{
SELECT (MAX(?vers) AS ?max) ?id_ WHERE {
?comment dct:identifier ?id_ ;
diff --git a/gn3/db/wiki.py b/gn3/db/wiki.py
index c3c68e0..4721a69 100644
--- a/gn3/db/wiki.py
+++ b/gn3/db/wiki.py
@@ -9,6 +9,16 @@ class MissingDBDataException(Exception):
"""Error due to DB missing some data"""
+def _decode_dict(result: dict):
+ new_result = {}
+ for k, v in result.items():
+ if isinstance(v, bytes):
+ new_result[k] = v.decode()
+ else:
+ new_result[k] = v
+ return new_result
+
+
def get_latest_comment(connection, comment_id: int) -> int:
""" Latest comment is one with the highest versionId """
cursor = connection.cursor(DictCursor)
@@ -20,7 +30,7 @@ def get_latest_comment(connection, comment_id: int) -> int:
ORDER BY versionId DESC LIMIT 1;
"""
cursor.execute(query, (str(comment_id),))
- result = cursor.fetchone()
+ result = _decode_dict(cursor.fetchone())
if (pubmed_ids := result.get("pubmed_ids")) is None:
pubmed_ids = ""
result["pubmed_ids"] = [x.strip() for x in pubmed_ids.split()]
@@ -31,7 +41,7 @@ def get_latest_comment(connection, comment_id: int) -> int:
"""
cursor.execute(categories_query, (str(comment_id), result["version"]))
- categories = cursor.fetchall()
+ categories = [_decode_dict(x) for x in cursor.fetchall()]
result["categories"] = [x["Name"] for x in categories]
return result