Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_or_update is creating a new node even if constraint of unique is given for the property #812

Open
aumcerebral opened this issue Jun 16, 2024 · 2 comments
Labels

Comments

@aumcerebral
Copy link

aumcerebral commented Jun 16, 2024

Expected Behavior (Mandatory)

I am ingesting a node again by bulk create_or_update option but while filtering, it still shows 2 nodes. Am i giving the right constraints?

How to Reproduce the Problem

class Person(StructuredNode):
    uid = UniqueIdProperty()
    name = StringProperty(unique_index=True, required =True)
    age = IntegerProperty(index=True, default=0)

jim = Person(name='Jill', age=3).save() 
people = [
    {'name': 'Tim', 'age': 83},
    {'name': 'Bob', 'age': 23},
    {'name': 'Jill', 'age': 34},
]

Person.create_or_update(*people)
people = Person.nodes.filter(name= "Jill")
people.all()

Screenshots (where it's possibile)

image

Specifications (Mandatory)

neomodel==5.3.1

Versions

  • OS: ubuntu 20.04

  • Neo4j: neo4j 4.1.13

@mariusconjeaud
Copy link
Collaborator

This is the same problem as #788 ; where get_or_create/create_or_update creates a Cypher MERGE, using unique properties as key. So in your case, both uid and name are used for the merge. But since you let neomodel create the uid, then you have two different Jill nodes, with different uids.

This is a wrong behaviour in neomodel in my opinion, as I can see that users would do as you did (let neomodel handle the uid creation); but I also understand the way those methods are built, so I will admit I am undecided about how to fix this.

@ziqizhang
Copy link

I'm also having this problem and I'd appreciate a workaround for updating behaviours for now.

At the moment, I made changes like the following:

class Person(StructuredNode):
    #uid = UniqueIdProperty()
    name = StringProperty(unique_index=True, required =True, primary_key=True)
    age = IntegerProperty(index=True, default=0)

And I do get the expected behaviour. But I don't know what the implications are. At least, I guess you need to make sure the 'name' is unique on every 'create/insert' operation to avoid integrity violations. But I don't now what happens to the uuid in this case, or does it really matter?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants