1

I am using the Neomodel Python package with the Neo4j database and loving it. I am currently using the filter() method, but every time I use the filter() method on a property not defined in the SemiStructuredNode I get an error.

In the example below I have my Person SemiStructuredNode with only surname as a property, but some nodes in the database might have eye_colour as well and I want to filter by that. Note that not all nodes will have eye colour.

class Person(SemiStructuredNode):
    surname = StringProperty()

Person.nodes.filter(surname__contains='atts',eye_colour='BLUE')

To me the code above should work but I get a ValueError: No such property eye_colour on Person error. However, if I change my class definition to include eye_colour as a StringProperty everything is fine. However, I do not want to do this because there are various other dynamic filters I want to use because of different data being imported into the system.

Does Neomodel support what I'm trying to do or will I have to build a Cypher query or can someone see what I'm getting wrong?

jelly5798
  • 349
  • 2
  • 9

1 Answers1

0

You should always use a try and except clause when dealing with this kind of exception.

try:
    Person.nodes.filter(surname__contains='atts',eye_colour='BLUE')
except:
    print ("Couldn't filter surname and eye_colour")
jose_bacoy
  • 12,227
  • 1
  • 20
  • 38
  • Catching the exception isn't an issue, I omitted my exception code on purpose. The issue is does the SemiStructuredNode support filtering on dynamic properties? – jelly5798 Mar 05 '21 at 09:19