-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Fixed #20581 -- Added support for deferrable unique constraints. #10338
Conversation
e63e6cd
to
d8786b7
Compare
52b99c3
to
f514cca
Compare
8e41e20
to
5eca9f8
Compare
is it ready for review? |
@auvipy Yes. |
1be10ff
to
af9caf3
Compare
@auvipy I've synced this with |
OK I will |
I haven't tested the Oracle support, because I don't have Oracle configured locally. I think it should work, from my reading of the docs, but it's possible something isn't quite right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great to merge.
@carltongibson @felixxm I'd like to land this today if possible. I think the main thing it needs is release notes. Is there anything else I need to do? |
IMO it should work on Oracle, can you enable |
9b7f86a
to
017ad48
Compare
As far as I can tell, MySQL and MariaDB do not support deferrable constraints. I've added a small release note and enabled this for Oracle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ian-Foote Thanks 👍 We have some failures on Oracle (with proposed changes):
test_add_deferrable_unique_constraint (migrations.test_operations.OperationTests)
,test_create_model_with_deferrable_unique_constraint (migrations.test_operations.OperationTests)
,test_remove_deferrable_unique_constraint (migrations.test_operations.OperationTests)
, and
raise
django.db.utils.IntegrityError: ORA-02091: transaction rolled back
ORA-00001: unique constraint (DJANGOTEST.DEFERRABLE_PINK_CONSTRAINT) violated
Also I think we should add a system checks for databases that don't support defferable
, like we added for condition
(ticket-31351).
eb86cc7
to
460337d
Compare
@Ian-Foote Thanks for updates 👍 I pushed small edits and:
I'm not convinced that we need I'm still fighting with Please don't use force-push if you will do any changes, it's harder to review such changes. |
+1 on enum removal. For the simple case of two single-word strings we end up with an extra object to import... |
I think it's better to keep the enum. It avoids the possibility of a typo. There is precident with things like passing Edit: or, if not an enum, at least an importable constant would be good. |
I originally used importable strings instead of the Enum and changed it in response to #10338 (comment). See also this discussion: #10338 (comment). At this point, I prefer the Enum over the other two options:
|
@meshy
That can be easily be handled by raising a - if deferrable is not None and not isinstance(deferrable, Deferrable):
+ if deferrable is not None and deferrable not in {'deferred', 'immediate'}: Removing the enum avoids having to import it in various places, including an inline import in the
That would be worse than an enum - you'd now need two constants and it wouldn't prevent use of an arbitrary string anyway as we would still have to validate the values as there would be no type checking. Whether an enum or multiple constants, this also requires additional documentation of these objects/constants rather than just stating the two accepted string values for the |
@Ian-Foote Sorry - we posted simultaneously.
As pointed out by @felixxm, there is the third option is to just use the string values Don't get me wrong - enums do have benefits, I'm just not sure that it is worth it in this instance when there are only two possible values, and when that means importing Anyway, that's just my 2¢ and I'll leave it at that. I see that @charettes was for the enum and am happy to go with his wisdom. |
Good point that I misunderstood @felixxm's suggestion. I think I still prefer the Enum slightly, but I don't feel as strongly as compared to the other two options. |
I don't have a strong feeling either way, using an |
I already reuse |
OK, let's stay with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ian-Foote Many thanks for your hard work and patience 🚀 It took several DjangoCon's 😉
I pushed final edits and fixed tests on Oracle.
|
Congrats @Ian-Foote and thank you for your continued efforts 🙇 🎉 ! |
This builds upon #10271, extending the
UniqueConstraint
class to support deferring constraint checks.https://code.djangoproject.com/ticket/20581