-
Notifications
You must be signed in to change notification settings - Fork 123
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
Calling Create where a deleted object violates uniqueness #185
Comments
I think In my case, I try to use partial unique constraints: UniqueConstraint(fields=['user'], condition=Q(deleted__isnull=True), name='unique_user') So only active instances are concerned by the unique constraint. Maybe we should document that, it's not the first time I see issue about uniqueness. |
Hmmm. But then what happens when you try to revive the deleted object? Or you query all_objects and suddenly get 2? Obviously I know the answers, but I'm building tools for people whom I don't expect to be familiar with
This would be great documentation to add. Would have been super helpful to me, and I'm debating going back and adding it in to my code.
I think this would be great. Something like:
What about making this an option on each model (default to no)?
|
Actually, would be much better to do:
There's probably a way to wrap it all up in one query, which I think is what you were suggesting about overwriting the model's check unique. I don't know much about it, but I'd be happy to look into it. |
People should at least know that their deleted objects are not, in fact, deleted. Imho it would be more confusing to create an object, only to find it already have things set (optional fields which come for the revived object and not set during the "creation").
I'll add that somewhere.
I still don't think this is a good idea, I think this should be done in a custom base model (and I'd actually prefer the |
Not entirely sure what you mean here. Something like this?
I also couldn't really figure out an easier way to raise the proper error other than the method I proposed above |
Yes something like that with your own |
Currently, we have overridden
update_or_create()
where it will undelete an object if a unique constraint is violated. I would expect similar behavior from acreate()
override, but this is not currently the case. At the very least, I would love an error informing that the object exists and has been deleted.Thoughts on implementing either of these options?
The text was updated successfully, but these errors were encountered: