Opened 5 years ago
Closed 4 years ago
#31410 closed Cleanup/optimization (fixed)
Add check for fields of UniqueConstraints.
Reported by: | Marnanel Thurman | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Ian Foote | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
When a model gains a UniqueConstraint
, makemigrations doesn't check that the fields named therein actually exist.
This is in contrast to the older unique_together
syntax, which raises models.E012 if the fields don't exist.
In the attached demonstration, you'll need to uncomment "with_unique_together"
in settings.py in order to show that unique_together
raises E012.
Attachments (2)
Change History (15)
by , 5 years ago
Attachment: | uniqueconstraint_bug.zip added |
---|
comment:1 by , 5 years ago
Component: | Uncategorized → Migrations |
---|
comment:2 by , 5 years ago
Description: | modified (diff) |
---|
comment:3 by , 5 years ago
Component: | Migrations → Database layer (models, ORM) |
---|---|
Easy pickings: | set |
Summary: | makemigrations doesn't check that UniqueConstraint field names exist → Add check for fields of UniqueConstraints. |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Agreed. We can simply call cls._check_local_fields()
for UniqueConstraint
's fields. I attached tests.
comment:4 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 6 comment:5 by , 5 years ago
Hello Django Team,
My name is Jannah Mandwee, and I am working on my final project for my undergraduate software engineering class (here is the link to the assignment: https://web.eecs.umich.edu/~weimerw/481/hw6.html). I have to contribute to an open-source project and was advised to look through easy ticket pickings. I am wondering if it is possible to contribute to this ticket or if there is another ticket you believe would be a better fit for me. Thank you for your help.
comment:6 by , 5 years ago
Replying to Jannah Mandwee:
Hello Django Team,
My name is Jannah Mandwee, and I am working on my final project for my undergraduate software engineering class (here is the link to the assignment: https://web.eecs.umich.edu/~weimerw/481/hw6.html). I have to contribute to an open-source project and was advised to look through easy ticket pickings. I am wondering if it is possible to contribute to this ticket or if there is another ticket you believe would be a better fit for me. Thank you for your help.
Hi Jannah, I'm working in this ticket. You can consult this report: https://code.djangoproject.com/query?status=!closed&easy=1&stage=Accepted&order=priority there are all the tickets marked as easy.
comment:7 by , 5 years ago
Cc: | added |
---|
comment:9 by , 5 years ago
Summary: | Add check for fields of UniqueConstraints. → Add check for fields of UniqueConstraints and CheckConstraint. |
---|
comment:10 by , 5 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
comment:11 by , 4 years ago
Patch needs improvement: | set |
---|---|
Summary: | Add check for fields of UniqueConstraints and CheckConstraint. → Add check for fields of UniqueConstraints. |
Version: | 3.0 → master |
Replying to Ian Foote:
CheckConstraint
might have the same bug.
After reconsideration I think we should limit this check only to UniqueConstraint
's, it's not worth to add complex and error prone logic for CheckConstraint
's, we can fail of custom expressions etc.
comment:12 by , 4 years ago
Patch needs improvement: | unset |
---|
CheckConstraint
checks removed from patch.
Demonstration