[Django] #35056: AttributeError: 'ManyToManyField' object has no attribute 'through'

36 views
Skip to first unread message

Django

unread,
Dec 21, 2023, 8:39:48 AM12/21/23
to django-...@googlegroups.com
#35056: AttributeError: 'ManyToManyField' object has no attribute 'through'
--------------------------------------------------+------------------------
Reporter: M.Eng. Thomas Feldmann | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------------+------------------------
I'm having problems updating my Django 4.2 project to Django 5.
Trying `manage.py runserver` raises an exception when performing system
checks:

{{{
Exception in thread django-main-thread:
Traceback (most recent call last):
File
"/opt/homebrew/Cellar/pyt...@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py",
line 1045, in _bootstrap_inner
self.run()
File
"/opt/homebrew/Cellar/pyt...@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py",
line 982, in run
self._target(*self._args, **self._kwargs)
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/core/management/commands/runserver.py", line 133, in
inner_run
self.check(display_num_errors=True)
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/core/management/base.py", line 485, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/checks.py", line 52, in check_admin_app
errors.extend(site.check(app_configs))
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/sites.py", line 89, in check
errors.extend(modeladmin.check())
^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/options.py", line 148, in check
return self.checks_class().check(self, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/checks.py", line 806, in check
*super().check(admin_obj),
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/checks.py", line 187, in check
*self._check_filter_horizontal(admin_obj),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/checks.py", line 515, in
_check_filter_horizontal
return list(
^^^^^
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/checks.py", line 517, in <genexpr>
self._check_filter_item(
File "/Users/tf/work/mama2/mama/.venv/lib/python3.11/site-
packages/django/contrib/admin/checks.py", line 539, in _check_filter_item
elif not field.remote_field.through._meta.auto_created:
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ManyToManyField' object has no attribute 'through'
}}}

The project works fine in Django 4.2.7.
I found this comes from a filter_horizontal field which is a
ManyToManyField's related_name.

--
Ticket URL: <https://code.djangoproject.com/ticket/35056>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 21, 2023, 12:12:43 PM12/21/23
to django-...@googlegroups.com
#35056: AttributeError: 'ManyToManyField' object has no attribute 'through'
-------------------------------------+-------------------------------------
Reporter: M.Eng. Thomas | Owner: nobody
Feldmann |

Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Thanks for the report. Can you provide a small project that reproduces the
issue?

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

Django

unread,
Dec 21, 2023, 1:36:13 PM12/21/23
to django-...@googlegroups.com
#35056: AttributeError: 'ManyToManyField' object has no attribute 'through'
-------------------------------------+-------------------------------------
Reporter: M.Eng. Thomas | Owner: nobody
Feldmann |
Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by M.Eng. Thomas Feldmann):

* Attachment "Archiv.zip" added.

Small reproduction example

Django

unread,
Dec 21, 2023, 1:39:23 PM12/21/23
to django-...@googlegroups.com
#35056: AttributeError: 'ManyToManyField' object has no attribute 'through'
-------------------------------------+-------------------------------------
Reporter: M.Eng. Thomas | Owner: nobody
Feldmann |
Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by M.Eng. Thomas Feldmann):

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for the report. Can you provide a small project that reproduces
the issue?

Sure. Added a small example. While putting this together I realized this
also doesn't work in Django 4 but does not raise an exception.
The error message could be a little clearer but I'm not sure whether this
is a bug or a feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/35056#comment:2>

Reply all
Reply to author
Forward
0 new messages