Use of batch create_or_update for a bunch of StructuredNode Objects, raises exception. I created a datamodel in a separate py file for this
Exception occurs:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/neomodel/properties.py", line 92, in deflate if properties.get(name) is not None: ^^^^^^^^^^^^^^ AttributeError: 'list' object has no attribute 'get'
Datamodel :
from neomodel import StructuredNode, StringProperty, RelationshipTo, RelationshipFrom, StructuredRel, DateProperty
class Dog(StructuredNode):
name = StringProperty(required=True)
owner = RelationshipTo('Person', 'owner')
class Person(StructuredNode):
name = StringProperty(unique_index=True)
pets = RelationshipFrom('Dog', 'owner')
Code
people = Person.create_or_update(
{'name': 'Tim', 'age': 83},
{'name': 'Bob', 'age': 23},
{'name': 'Jill', 'age': 34},
)
listPersons = []
listPersons.append(Person(name= 'Susan'))
listPersons.append(Person(name='Bob'))
Person.create_or_update(listPersons)
Does anyone knows what I'm doing wrong?
The error you're encountering is because create_or_update method in
Neomodelexpects dictionaries (e.g., keyword arguments) for creating or updating nodes, but you're passing a list of Person objects instead.To batch create or update StructuredNode objects using
create_or_update, you should pass dictionaries containing the property values for each node you want to create or update.Here's how you can modify your code to achieve this:
In the code above, we create a list of dictionaries (one for each person) and then pass that list as arguments to
Person.create_or_update. The*peoplesyntax is used to unpack the list into separate arguments.Additionally, if you want to create or update individual Person objects and not use batch processing, you can do it like this:
In this case, we iterate through the list of dictionaries and use
**person_datato pass each dictionary as keyword arguments toPerson.create_or_update.