[Django] #36973: fields.E348 check should check against the accessor_name instead of the model name

4 views
Skip to first unread message

Django

unread,
Mar 5, 2026, 10:39:46 PM (2 days ago) Mar 5
to django-...@googlegroups.com
#36973: fields.E348 check should check against the accessor_name instead of the
model name
-------------------------------------+-------------------------------------
Reporter: nick.ma@… | Type: Bug
Status: new | Component: Core
| (System checks)
Version: 6.0 | Severity: Normal
Keywords: System checks, | Triage Stage:
fields.E348, related_name | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
when running manage.py I hit erroneous fields.E348 check. The system check
is supposed to examine if ManyToOne/ManyToMany field <related_name> for
<model>.<field name> clashes with the name of a model manager. However,
instead of checking the related_name (i.e. <fieldname>_set or manually set
related_name=<related_name>) it gets the actual field name of the foreign
key.

As shown in the original check function below

{{{
def _check_conflict_with_managers(self):
errors = []
manager_names = {manager.name for manager in self.opts.managers}
for rel_objs in self.model._meta.related_objects:
related_object_name = rel_objs.name
if related_object_name in manager_names:
field_name = f"{self.model._meta.object_name}.{self.name}"
errors.append(
checks.Error(
f"Related name '{related_object_name}' for
'{field_name}' "
"clashes with the name of a model manager.",
hint=(
"Rename the model manager or change the
related_name "
f"argument in the definition for field
'{field_name}'."
),
obj=self,
id="fields.E348",
)
)
return errors
}}}

it compares a model's managers' name and its related object field name.

{{{ related_object_name = rel_objs.name }}}

**Patch:**
It should use the .accessor_name instead of .name
{{{
diff --git a/django/db/models/fields/related.py
b/django/db/models/fields/related.py
index f1bc664007..a3ef912a8e 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -723,7 +723,7 @@ class ForeignObject(RelatedField):
errors = []
manager_names = {manager.name for manager in self.opts.managers}
for rel_objs in self.model._meta.related_objects:
- related_object_name = rel_objs.name
+ related_object_name = rel_objs.accessor_name
if related_object_name in manager_names:
field_name =
f"{self.model._meta.object_name}.{self.name}"
errors.append(
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36973>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 5, 2026, 11:14:04 PM (2 days ago) Mar 5
to django-...@googlegroups.com
#36973: fields.E348 check should check against the accessor_name instead of the
model name
-------------------------------------+-------------------------------------
Reporter: nick.ma@… | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: System checks, | Triage Stage:
fields.E348, related_name | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shubh Rai):

* component: Core (System checks) => Database layer (models, ORM)
* owner: (none) => Shubh Rai
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36973#comment:1>

Django

unread,
Mar 6, 2026, 4:33:37 AM (22 hours ago) Mar 6
to django-...@googlegroups.com
#36973: fields.E348 check should check against the accessor_name instead of the
model name
-------------------------------------+-------------------------------------
Reporter: nick.ma@… | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: System checks, | Triage Stage:
fields.E348, related_name | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shubh Rai):

* cc: Shubh Rai (added)

Comment:

I have made a pr: https://github.com/django/django/pull/20846 . Please
feel free to tell me any changes that are required , any feedback would be
appreciated.
--
Ticket URL: <https://code.djangoproject.com/ticket/36973#comment:2>
Reply all
Reply to author
Forward
0 new messages