You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @motey. Thanks for raising this, I can see that it's a valid gap in the functionality. Your proposal feels like it's along the right lines, but I'm going to give some thought to slightly broader functionality around reflection of GraphObjects. Watch this space.
I am trying to inspect a py2neo.ogm.GraphObject subclass. I want to check if a certain class attribute is a py2neo.ogm.Property:
This will fail as with
getattr(Entity, "name")
py2neo.ogm.Property.__get__()
will be called and raises anAttributeError: 'NoneType' object has no attribute '__node__'
One workaround is to check my classes
__dict__
This will return '<class 'py2neo.ogm.Property'>'
Now i know that Entity.name is py2neo.ogm.Property. Nice...But:
This will fail as soon the Property is inherited.
This will fail with a "KeyError: 'name'" as 'name' is in the superclass Entity.
I could now start to traverse all subclasses and search for the attr.
Another solution is to add an instance check to all py2neo.ogm descriptors
py2neo/internal/ogm.py[z41]:
now we easily could create a neat helper func like:
Related discussion on stackoverflow:
https://stackoverflow.com/questions/21629397/neat-way-to-get-descriptor-object
I will create a merge request for the changes.
The text was updated successfully, but these errors were encountered: