#28110: Model inheritance field name collision check error refers to related
accessors as fields
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Core (System | Version: 1.11
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Clifford Gama):
The issue here is about how:
{{{#!python
from django.db import models
class Parent(models.Model):
pass
class Child(models.Model):
child = TextField()
}}}
`myapp.Child.child: (models.E006) The field 'child' clashes with the field
'child' from model 'myapp.parent'.` which is intended and tested behavior
in Django.
The issue being that `Parent.child` is not a field.
However:
{{{#!shell
>>>from myapp.models import Parent
>>>c = Parent._meta.get_field("child")
>>>assert c is not None # Which is why it's being reported as one, I
think
>>>c
<OneToOneRel: myapp.child>
}}}
After considering the options:
1. We add a note specifying that shadowing the reverse accessor in
subclasses is not allowed. This option would add clarity but doesn't solve
the problem directly. While useful, it doesn't address the fact that the
error message is misleading by treating the reverse accessor like a field.
This solution would not directly resolve the misunderstanding caused by
the current error message.
2. Two messages in the check models.006, depending on whether the clash is
between a field and a field or a field and an accessor. This approach
would overload models.E006 to handle two separate cases, which I don't
believe acceptable. (Each check ID for a single check.)
3. Create a new models.00xx error for this specific check. This option
would maintain clear separation between different checks. However, it may
be over-engineering for this small issue, and may lead to a bit more
overhead in terms of adding and managing error codes.
4. Change the error message to: `"myapp.Child.child: (models.E006) The
field 'child' clashes with the field or accessor 'child' from model
'myapp.parent'"` which accounts for the accessors.
I'm inclined to go with 4. Adding a note in the docs as well. LMKWYT
--
Ticket URL: <https://code.djangoproject.com/ticket/28110#comment:8>
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/010701930b68749f-d95118f3-edb2-4ab0-9829-6a6d63f96bd0-000000%40eu-central-1.amazonses.com.