#31442 closed Bug (invalid)
Inherited ManyToMany.all() empty with multiple inherited models of same name from abstract one
| Reported by: | Gereon Kremer | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Please see #24156 first!
The issue described there still persists if the derived model classes have the same class name (spread across different apps).
I understand this to be a weird model design at least, but found it to be reasonable for my current project.
I'd suggest to either use the fully qualified class name (i.e. app.model_class instead of model_class) to build the related_name, or at least note in the documentation that models with identical names can be a problem with inheritance.
Attachments (1)
Change History (5)
comment:2 by , 6 years ago
Sure, see the new attachment.
Running ./manage.py makemigrations yields
SystemCheckError: System check identified some issues:
ERRORS:
appA.Stuff.owners: (fields.E305) Reverse query name for 'Stuff.owners' clashes with reverse query name for 'Stuff.owners'.
HINT: Add or change a related_name argument to the definition for 'Stuff.owners' or 'Stuff.owners'.
appB.Stuff.owners: (fields.E305) Reverse query name for 'Stuff.owners' clashes with reverse query name for 'Stuff.owners'.
HINT: Add or change a related_name argument to the definition for 'Stuff.owners' or 'Stuff.owners'.
comment:3 by , 6 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
OK, thanks. So the system check error that spells out the problem:
$ ./manage.py makemigrations SystemCheckError: System check identified some issues: ERRORS: app1.Child.field1: (fields.E305) Reverse query name for 'Child.field1' clashes with reverse query name for 'Child.field1'. HINT: Add or change a related_name argument to the definition for 'Child.field1' or 'Child.field1'. app2.Child.field1: (fields.E305) Reverse query name for 'Child.field1' clashes with reverse query name for 'Child.field1'. HINT: Add or change a related_name argument to the definition for 'Child.field1' or 'Child.field1'.
See the docs section: Be careful with related_name and related_query_name. Specify something like related_name="%(app_label)s_%(class)s_related" on the ManyToManyField on the abstract model.
Hi Gereon — are you able to upload a sample project reproducing this? (I can try to recreate from the description but it's a bit incomplete.)
Seems plausible though...