Skip to content

Instantly share code, notes, and snippets.

@anatoly-scherbakov
Last active November 14, 2021 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatoly-scherbakov/e7baee765ca9f22f419a2eb5a89689e8 to your computer and use it in GitHub Desktop.
Save anatoly-scherbakov/e7baee765ca9f22f419a2eb5a89689e8 to your computer and use it in GitHub Desktop.
rdflib-sqlalchemy fails if attempted to find a triple with a Literal subject in the graph
import logging
from sys import version as python_version
from rdflib import ConjunctiveGraph, Literal, URIRef, OWL, RDFS
from rdflib import __version__ as rdflib_version
from rdflib import plugin
from rdflib.store import Store
from rdflib_sqlalchemy import __version__ as rdflib_sqlalchemy_version
logger = logging.getLogger(__name__)
def test_sqlalchemy_obj_language():
logger.info(f'Python version: {python_version}')
logger.info(f'RDFLib version: {rdflib_version}')
logger.info(f'RDFLib-SQLAlchemy version: {rdflib_sqlalchemy_version}')
identifier = URIRef('local://test_sqlalchemy_obj_language/')
store = plugin.get(
'SQLAlchemy',
Store,
)(
identifier=identifier,
)
graph = ConjunctiveGraph(
store=store,
identifier=identifier,
)
graph.open('sqlite:///', create=True)
triple = (
URIRef('https://foo'),
RDFS.comment,
Literal('', lang='en'),
)
is_in_graph = triple in graph
@anatoly-scherbakov
Copy link
Author

anatoly-scherbakov commented Nov 13, 2021

FAILED     [100%]
2021-11-14 16:07:49,292 [INFO] tests.test_experiments.test_sqlalchemy_obj_language: Python version: 3.8.1 (default, Feb 21 2020, 23:12:01) 
[GCC 9.2.1 20191008]
2021-11-14 16:07:49,293 [INFO] tests.test_experiments.test_sqlalchemy_obj_language: RDFLib version: 6.0.2
2021-11-14 16:07:49,293 [INFO] tests.test_experiments.test_sqlalchemy_obj_language: RDFLib-SQLAlchemy version: 0.4.0

tests/test_experiments/test_sqlalchemy_obj_language.py:12 (test_sqlalchemy_obj_language)
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/sqlalchemy/sql/base.py:1219: in __getattr__
    return self._index[key]
E   KeyError: 'objLanguage'

The above exception was the direct cause of the following exception:
test_sqlalchemy_obj_language.py:40: in test_sqlalchemy_obj_language
    is_in_graph = triple in graph
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/rdflib/graph.py:1576: in __contains__
    for t in self.triples((s, p, o), context=c):
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/rdflib/graph.py:1650: in triples
    for (s, p, o), cg in self.store.triples((s, p, o), context=context):
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/rdflib_sqlalchemy/store.py:511: in triples
    selects = self._triples_helper(triple, context)
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/rdflib_sqlalchemy/store.py:479: in _triples_helper
    clause = self.build_clause(asserted, subject, predicate, obj, context)
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/rdflib_sqlalchemy/base.py:103: in build_clause
    self.build_literal_language_clause(obj, table)
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/rdflib_sqlalchemy/base.py:122: in build_literal_language_clause
    return table.c.objLanguage == obj.language
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/sqlalchemy/sql/base.py:1221: in __getattr__
    util.raise_(AttributeError(key), replace_context=err)
../../../../.pyenv/versions/octadocs/lib/python3.8/site-packages/sqlalchemy/util/compat.py:207: in raise_
    raise exception
E   AttributeError: objLanguage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment