Prevent crash when comparing ill-typed numeric types. #2949
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes comparisons that look like:
Both of the dataypes are in the
_NUMERIC_LITERAL_TYPES
list, so they enter the fast-path comparison.The problem is the second literal is not a valid integer, so it has the value
None
.That throws a comparison error that is uncaught by RDFLib, causing the application to crash.
If this seems like something that is pretty common and should be picked up sooner, I think its because this error only occurs when
rdflib.NORMALIZE_LITERALS
is False. When rdflib normalizes the literals, it fixes the value, so this does not happen. I found this when testing some PySHACL code sections which run withrdflib.NORMALIZE_LITERALS=False
.Luckily since rdflib introduced the concept of
ill_typed
literals, we can use that to restrict the fast-path to only those numeric literals that are not ill-typed.