neo4j-contrib / neomodel

An Object Graph Mapper (OGM) for the Neo4j graph database.
https://neomodel.readthedocs.io
MIT License
939 stars 231 forks source link

Use of batch create_or_update raises Exception #747

Closed mdurieux closed 10 months ago

mdurieux commented 12 months ago

Description

Use of batch create_or_update for a bunch of StructuredNode Objects

Expected behaviour

Neo4j populated

Actual behaviour

Exception occurs: Traceback (most recent call last): File "/Users/myUser/git-python/neo4j-lab01/src/myfolder/PopulateNeo4jFromHeliosDevGithub.py", line 49, in Person.create_or_update(listPersons) File "/opt/homebrew/lib/python3.11/site-packages/neomodel/core.py", line 509, in create_or_update for specified, deflated in [ ^ File "/opt/homebrew/lib/python3.11/site-packages/neomodel/core.py", line 510, in (p, cls.deflate(p, skip_empty=True)) for p in props ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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'

Steps to reproduce

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 :

with db.transaction:

###### This code is working fine
people = Person.create_or_update(
    {'name': 'Tim', 'age': 83},
    {'name': 'Bob', 'age': 23},
    {'name': 'Jill', 'age': 34},
)
######

###### The code hereunder does raise Exception above

listPersons = []
listPersons.append(Person(name= 'Susan'))
listPersons.append(Person(name='Bob'))
Person.create_or_update(listPersons)

Additional info:

Output of the commands:

aanastasiou commented 12 months ago

@mdurieux Please see relevant documentation, create_or_update does not expect a list. Do you think that this answers your question or was there something I did not get?

mariusconjeaud commented 11 months ago

Moving to #583