Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling .save() or is_present() methods of Resource raise exception #1

Closed
mromanello opened this issue Feb 13, 2019 · 2 comments
Closed

Comments

@mromanello
Copy link
Collaborator

mromanello commented Feb 13, 2019

For the full description see issue on upstream repo.

Here you can see an example of how the code fails (this refers to the Python3 branch of hucitlib and uses your py3-compliant version of surf; however, I reproduce the same error with surf==1.2.0 and hucitlib master branch. With surf==1.1.9 all works fine).

PS: the fact that the surf repo does not have releases makes it difficult for me to do some debugging with a locally modified version of 1.1.9 and 1.2.0, and compare the two behaviours.

@mromanello
Copy link
Collaborator Author

Just a brief update: I've found the problematic line and how to make it work, but I'm not 100% sure about the logic.

The problematic line is this if/else block:

if isinstance(statement, (list, tuple)):
try:
s, p, o = statement
except:
raise ValueError('''Statement of type [list, tuple] does not
have all the (s,p,o) members (the length of the
supplied arguemnt must be at least 3)''')
if isinstance(s, (URIRef, BNode)) or (isinstance(s, basestring) and s.startswith('?')):
pass
else:
raise ValueError('The subject is not a valid variable type')
if isinstance(p, URIRef) or (isinstance(p, basestring) and p.startswith('?')):
pass
else:
raise ValueError('The predicate is not a valid variable type')
if isinstance(o, (URIRef, BNode, Literal)) or (isinstance(o, basestring) and o.startswith('?')):
pass
else:
raise ValueError(u'The object is not a valid variable type: {0:s}'.format(o))
return True
else:
raise ValueError('Statement type not in {0:s}'.format)

Take a statement like

[('?s', '?p', '?o'), u'(?s = <http://purl.org/hucit/kb/authors/927/cts_urn>)']

In the version of surf that still works (1.1.9) the type is checked using

if type(statement) in [list, tuple]

which for the statement above returns False.

In version 1.2.0 the line has been changed into

isinstance(statement, (list, tuple))

which now returns True for the same statement. If I change that line to how it previously was, all works fine, but I do not understand why this difference between isinstance and type.

PS: the type of statement is NamedGroup, which is a subclass of Group, which is a subclass of list. Perhaps what's happening is that using isinstance here has the side effect of capturing this inheritance between classes (which is AFAIU unintentional)?

@PonteIneptique
Copy link
Owner

PonteIneptique commented Feb 13, 2019 via email

PonteIneptique added a commit that referenced this issue Feb 14, 2019
ravenscroftj referenced this issue in ravenscroftj/surfrdf Oct 28, 2019
Add escape for backslashes
PonteIneptique added a commit that referenced this issue Apr 22, 2020
changing type checking (see issue #1) as per Thibault's suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants