From 8d468dd26f4637bc7ea218afbed159b741f982e9 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Thu, 7 Jul 2022 18:13:30 +0100 Subject: [PATCH] Avoid raising unrelated AttributeError ... from attempting to access language and datatype attributes of non-Literal objects --- rdflib/plugins/sparql/operators.py | 4 ++-- test/test_issues/test_issue1873.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/test_issues/test_issue1873.py diff --git a/rdflib/plugins/sparql/operators.py b/rdflib/plugins/sparql/operators.py index e56febbb6..0f7b53255 100644 --- a/rdflib/plugins/sparql/operators.py +++ b/rdflib/plugins/sparql/operators.py @@ -298,10 +298,10 @@ def Builtin_CONCAT(expr, ctx): # dt/lang passed on only if they all match - dt = set(x.datatype for x in expr.arg) + dt = set(x.datatype for x in expr.arg if isinstance(x, Literal)) dt = dt.pop() if len(dt) == 1 else None - lang = set(x.language for x in expr.arg) + lang = set(x.language for x in expr.arg if isinstance(x, Literal)) lang = lang.pop() if len(lang) == 1 else None return Literal("".join(string(x) for x in expr.arg), datatype=dt, lang=lang) diff --git a/test/test_issues/test_issue1873.py b/test/test_issues/test_issue1873.py new file mode 100644 index 000000000..2e42d26e5 --- /dev/null +++ b/test/test_issues/test_issue1873.py @@ -0,0 +1,9 @@ +from rdflib import Graph + + +def test_sparql_error_implicit_bind(): + [r for r in Graph().query('SELECT (concat("", sha1(?x)) AS ?y) WHERE {}')] + + +def test_sparql_error_explicit_bind(): + [r for r in Graph().query("SELECT ?v ?p ?m WHERE {?v ?p ?m BIND (sha1(?x) AS ?m)}")]