#36530: System check for ManyToManyField & Composite Primary Key checks only one
direction
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jason
| Hall
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: compositeprimarykey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jason Hall):
I was just trying to reproduce this issue with the following test:
{{{
@isolate_apps("model_fields")
class M2MCompositePKCheckTests(SimpleTestCase):
def test_m2m_from_model_composite_pk_should_raise_e347(self):
class Target(models.Model):
name = models.CharField(max_length=100)
class Meta:
app_label = "model_fields"
class TimeStamped(models.Model):
id = models.IntegerField()
created = models.DateTimeField()
tenants = models.ManyToManyField(Target)
class Meta:
app_label = "model_fields"
constraints = [
models.UniqueConstraint(fields=["id", "created"],
name="composite_pk")
]
errors = TimeStamped.check()
self.assertTrue(
any(e.id == "models.E347" for e in errors),
msg="Expected E347 for ManyToManyField declared on a model
with composite primary key",
)
}}}
I'm not sure if this approach (using UniqueConstraint to simulate a
composite PK) is appropriate for the final test, or if we should prefer
the version that uses CompositePrimaryKey and field.check(from_model=...).
Just wanted to share what I came up with to help confirm the issue before
working on the fix. Happy to adjust based on feedback!
--
Ticket URL: <https://code.djangoproject.com/ticket/36530#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019851a47d09-b1a71963-db96-45ab-a930-b26550b71572-000000%40eu-central-1.amazonses.com.