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 does not allow for specifying what unique fields to match #828

Open
arg3t opened this issue Sep 13, 2024 · 1 comment
Open

Comments

@arg3t
Copy link

arg3t commented Sep 13, 2024

Problem

Currently, it is not possible to specify on what fields you want to apply the merge action when calling create_or_update. Meaning if you have a StructuredNode with two unique fields pk and name. And you want to update only based on name (don't have access to pk). You can't really update all at once using create_or_update, or you need to resort to an ugly hack:

...
Node.__required_properties__ = tuple([x for x in Node.__required_properties__ if x != "pk"])
Node.create_or_update(data)
...

Django's bulk_update has a similar feature, using unique_fields when calling bulk_create with update_conflicts=True.

https://docs.djangoproject.com/en/5.1/ref/models/querysets/#bulk-create

Solution

It should be fairly simple to add a parameter to select which required properties to use. Backwards compatibility can be supported by using required_properties if parameter is not specified.

@mariusconjeaud
Copy link
Collaborator

Related to #807

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

No branches or pull requests

2 participants