Unintuitive errors on nested queries
I have facts that are declared over python objects like this (simplified) example:
from pyDatalog import pyDatalog class Something(): pass s = Something() pyDatalog.create_terms('pred') +pred(s)
This works just fine. However, if the object itself tries to do stuff based on information from pyDatalog, we get a pretty unhelpful error like this:
<repr(<pyDatalog.pyParser.Query at 0x7f7f9680f2b0>) failed: AttributeError: 'NoneType' object has no attribute 'append'>
An example for this is if the object declares a rich __eq__ method to check for equality based on facts declared for this object.
Then whenever we have (O1 == O2) in the query, we get the error above, which I imagine happens because during the answering of the original query, a pyEngine.ask() is called a second time.
Another example is if the object's __str__ uses queries to describe itself (since pyDatalog uses the object's textual representation internally)
To make matters worse, if the query is inside of a function and you just check the used variables for content, you won't even see there was an error. Like this:
query_that_calls_nested_query(X) print(X.data) # the query silently failed and we didn't see it
In order to actually see it, you have to check for the return of the query direcly, since the query "masks" the exception as a result.
Ideally, I imagine pyDatalog could support nested queries, but since I see that the code is full of globals, I guess it would be pretty hard to realize. If that assumption is correct, I'd suggest at least two things
- make pyEngine.ask() check if it's a nested call and abort with a descriptive error and a full traceback (as opposed to this "hidden" query error)
- add a tip to the documentation about this limitation (sorry if there is already a mention to it, but I couldn't find it). Bonus points if you can list exactly what methods in an object must not include queries (at least __str__, __eq__, maybe __contains__?)
Also, feel free to downgrade this to an "enhancement" if you feel it better describes the issue. I was just a bit frustrated after hours of bug hunting ;)
PS.: this is not a regression, it affects both 0.14.5 and 0.14.6