UniqueTogetherValidator fails validating partial unique constraint when there is a nullable FK #9777
Unanswered
sevdog
asked this question in
Potential Issue
Replies: 2 comments 3 replies
-
is this PR related #9766 ? |
Beta Was this translation helpful? Give feedback.
1 reply
-
PS: in my project the setup is a bit more complex because I have 4 FKs (A,B,C,D) which should form two families of unique sets (A,B,C) when D is NULL and (A,B,D) when C is NULL. In my branch I have reduced to two FK with a value for simplicity. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In one of my projects I have a model which defines a set of nullable foreign-keys and a value which is unique according to how FKs are defined, like the following:
When validating this model using a
ModelSerializer
providing an input which triggers an error on one of those constraint I am not getting any error inserializer.is_valid()
.Here is a commit which adds a test case which fails with the current implementation: a4a3093
By debugging the problem seems to be how the query is build, because when executing the same query as in
qs_exists_with_condition
I get the following error (which is masked by the function and thus the validation prodives a false negative!):This problems forces me to rewrite the validation for the constraint which results in an extra query which is performed against the database.
Beta Was this translation helpful? Give feedback.
All reactions