Re: [Django] #34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields with intermediary models.

8 views
Skip to first unread message

Django

unread,
Feb 17, 2023, 1:37:47 AM2/17/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
--------------------------------------+------------------------------------
Reporter: David Pratten | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 4.1
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 David Pratten):

Thanks. Sounds like a good outcome.

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

Django

unread,
Feb 17, 2023, 1:51:33 AM2/17/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
--------------------------------------+------------------------------------
Reporter: David Pratten | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 4.1
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 Mariusz Felisiak):

Replying to [comment:3 David Pratten]:


> Thanks. Sounds like a good outcome.

Would you like to prepare a patch via GitHub PR? The following should
work:
{{{#!diff
diff --git a/django/contrib/admin/checks.py
b/django/contrib/admin/checks.py
index 27537d9614..a844b3f16f 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -533,6 +533,16 @@ class BaseModelAdminChecks:
return must_be(
"a many-to-many field", option=label, obj=obj,
id="admin.E020"
)
+ elif not field.remote_field.through._meta.auto_created:
+ return [
+ checks.Error(
+ f"The value of '{label}' cannot include the
ManyToManyField "
+ f"'{field_name}', because that field manually
specifies a "
+ f"relationship model.",
+ obj=obj.__class__,
+ id="admin.E013",
+ )
+ ]
else:
return []

}}}
Tests and [https://docs.djangoproject.com/en/stable/ref/checks/#admin docs
changes] (in the `admin.E013` description) are also required.

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:4>

Django

unread,
Feb 17, 2023, 4:38:24 AM2/17/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner: David
Type: | Pratten
Cleanup/optimization | Status: assigned

Component: contrib.admin | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by David Pratten):

* owner: nobody => David Pratten
* status: new => assigned


Comment:

Ok I'll take this up.

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:5>

Django

unread,
Feb 17, 2023, 4:56:12 AM2/17/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner: David
Type: | Pratten
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
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 David Pratten):

Replying to [comment:4 Mariusz Felisiak]:

I'm happy to work through this, but it won't be quick.

- Are we redefining {{{admin.E013}}} there seems to already be a
description of this error?
- Could you direct me to an explanation of where the documentation for the
errors is held and how it is updated?
- Could you direct me to an explanation of how to add a test case?

Thanks

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:6>

Django

unread,
Feb 17, 2023, 5:21:54 AM2/17/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner: David
Type: | Pratten
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
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 Mariusz Felisiak):

Replying to [comment:6 David Pratten]:


> - Are we redefining {{{admin.E013}}} there seems to already be a
description of this error?
> - Could you direct me to an explanation of where the documentation for
the errors is held and how it is updated?

We want to add `filter_vertical[n]` and `filter_horizontal[n]` to the
existing error `admin.E013` that is documented in
[https://github.com/django/django/blob/8eef22dfed2d53df0da10c0090d9cb04f66efb15/docs/ref/checks.txt#L637-L639
docs/ref/checks.txt], so we need to update the message in docs to the:

''"`fields[n]/filter_horizontal[n]/filter_vertical[n]/fieldsets[n][m]`
cannot include the `ManyToManyField` `<field name>`, because that field
manually specifies a relationship model."''

Docs are wrapped at 79 chars.

> - Could you direct me to an explanation of how to add a test case?

I would add test methods to the
`tests.modeladmin.test_checks.FilterHorizontalCheckTests` and
`tests.modeladmin.test_checks.FilterVerticalCheckTests`.

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:7>

Django

unread,
Mar 31, 2023, 1:47:20 AM3/31/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner: David
Type: | Pratten
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Natalia Bidart (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:8>

Django

unread,
May 4, 2023, 8:41:27 AM5/4/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner: David
Type: | Pratten
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
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 Natalia Bidart):

Hello David, would you have time to work on this? Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:9>

Django

unread,
Jun 15, 2023, 5:23:30 AM6/15/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner:
Type: | Hrushikesh Vaidya

Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by Hrushikesh Vaidya):

* owner: David Pratten => Hrushikesh Vaidya


Comment:

Since David seems to be busy, I'll try to take this up.

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:10>

Django

unread,
Jun 19, 2023, 10:23:44 PM6/19/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
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 Hrushikesh Vaidya):

[https://github.com/django/django/pull/16983 PR] ready for review

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:11>

Django

unread,
Jun 20, 2023, 5:28:04 AM6/20/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:12>

Django

unread,
Jun 21, 2023, 2:00:17 AM6/21/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:13>

Django

unread,
Jun 21, 2023, 2:54:16 AM6/21/23
to django-...@googlegroups.com
#34345: Add system check for filter_horizontal/filter_vertical on ManyToManyFields
with intermediary models.
-------------------------------------+-------------------------------------
Reporter: David Pratten | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"107865780aa44914e21d27fdf4ca269bc61c7f01" 10786578]:
{{{
#!CommitTicketReference repository=""
revision="107865780aa44914e21d27fdf4ca269bc61c7f01"
Fixed #34345 -- Added system check for ManyToManyFields with intermediate
tables in ModelAdmin.filter_horizontal/vertical.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:14>

Reply all
Reply to author
Forward
0 new messages