Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Fix unique together validator doesn't respect condition's fields#9360
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
@kalekseev - Could you talk me through this? My understanding is that it's resolving an issue in#7438, is that correct? |
kalekseev commentedMay 16, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
UPDATE: Yes, this pr is supposed to fix the initial implementation of UniqueConstraint support but at the moment it doesn't work. The problem is that DRF doesn't check if fields in data match the unique constraint condition or not, so for example constraint is:
we have record in db that should be unique
The data below should be valid because it has
but this should fail
|
fcc7c8d
to472a323
Compare0a64365
to9b7db30
Compare
@tomchristie I think this PR is ready for review, I described issue in previous comment, the fix is here https://github.com/encode/django-rest-framework/pull/9360/files#diff-9240f7dfb9eb2cace23eef00e4c922d6e2b6e85dc58b3c9d804e78c6c6227614R27-R34 the rest is just support code to perform that check (make sure that conditional fields values are present in serializer to perform check against condition). The condition check is actually copy of code fromhttps://github.com/django/django/blob/7ba2a0db20c37a5b1500434ca4ed48022311c171/django/db/models/constraints.py#L672 |
9b7db30
to5a3794b
Comparewe have this separate PR which seems to fix a regression, can you guys please check?#9482 |
MaxNstk commentedSep 30, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I do not know how the situation is right now but I noticed that when upgrading from the 3.14.0 version to 3.15.2 my condition started to broke. Here is the model: `
` In the current state it stops to check the condition is_active=True and raises and exception if I try to create a new record with is_active=False for the same date. |
SorianoMarmol commentedOct 23, 2024
Is a new version expected with this fix and others related like#9531? The support for UniqueConstraint is not complete and may cause issues… |
auvipy left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
can you please re base again? we got a separate PR merged
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.
This PR looks ready to be merged (after the rebase), but I've added a few code suggestions.
None of the suggestions are blocking (except maybe removingprint
in the tests) but in general they all serve the purpose of improving the code itself, or the Git history.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
we need to fix the following failing test as well
FAILED tests/test_validators.py::TestUniqueConstraintValidation::test_unique_together_condition_fields_required
=========== 1 failed, 1542 passed, 13 skipped, 5 warnings in 18.20s ============
py38-django42:
2fd3b45
to71ba738
Compare@auvipy rebased |
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.
what do you think about this change?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
71ba738
to59dd379
Compare17e9560
intoencode:masterUh oh!
There was an error while loading.Please reload this page.
@auvipy No. I'm not comfortable with the way this has been merged, completely unclear behavior. |
ops! Ok sorry! I thought comments were addressed! Going to revert this ASAP |
Please do. We're really clear on#9130 This project should be neatly parked. |
@tomchristie@auvipy I believe I addressed all comments as good as I can. If you have direct question I'm ready to answer them while I'm on that. |
It was a django orm compatibility PR. But doing anyway |
We're really clear on#9130 This project should be neatly parked. |
I thought that this PR fitted in the first category "Tracking any changes required by updates in Django versions" as Django replaces |
sipa-echo-zaoa commentedApr 1, 2025
Hi@kalekseev, thank you for your work. I think I found an issue in the way the serializer fields validator are being generated.
Trying running the tests result in the following errors:
Is this an expected behaviour or am I missing something? |
Do you think you could start a pull request with a failing test reproducing your problem? That might help us get the conversation going... |
sipa-echo-zaoa commentedApr 2, 2025
Hi@browniebroke I've created the#9678 merge request reproducing the problem. |
fixes#9358