Re: [Django] #34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is added via in another field using the "plus" JS action

28 views
Skip to first unread message

Django

unread,
Aug 21, 2023, 11:39:56 PM8/21/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* cc: David Sanders, Marcelo Galigniana (added)


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

Django

unread,
Aug 23, 2023, 1:08:51 PM8/23/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned

Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------
Changes (by devin13cox):

* owner: nobody => (none)
* status: new => assigned


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

Django

unread,
Aug 24, 2023, 3:13:26 AM8/24/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------

Comment (by David Sanders):

Replying to [ticket:34789 devin13cox]:
> My initial guess is that updating the query to not include the "Chosen"
column in filter_horizontal fields would solve this issue (something like
> {{{
> const selectsRelated = document.querySelectorAll(`[data-model-
ref="${modelName}"] div:not(.selector-chosen) > select:not(.admin-
autocomplete)`);
> }}}

That could work 👍 I'm just wondering though whether there's a better
approach than to continuously blacklist ancestors as we come across these
🤔

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

Django

unread,
Aug 27, 2023, 3:01:38 PM8/27/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------

Comment (by yokeshwaran1):

Hi David,
Im new to this repo, so I appreciate any guidance or feedback u can
offer.

Regardin issue with filter_horizontal "Chosen" column. From the
discussion, I think about a solution which will not continuously
blacklisting ancestors

1. Adding a data attribute like data-context to select elements during its
render phase in the Django admin templates. So each select will have a
more specific context about its purpose (eg. source, target, chosen etc.).

2. Then modifying the query in RelatedObjectLookups.js to use this new
data-context attribute, so our selector will become:

{{{
const selectsRelated = document.querySelectorAll(`[data-model-

ref="${modelName}"][data-context="source"] select:not(.admin-
autocomplete)`);
}}}

This approach will provide clear context for each select element which
makes JavaScript logic more intentional. would this be a feasible,
acceptable solution in ur opinion? I'm eager to hear ur thoughts & make
any necessary adjustments. Once approach is approved, I'm interested in
working on this ticket. Please let me know if that's possible.

Replying to [comment:8 David Sanders]:


> Replying to [ticket:34789 devin13cox]:
> > My initial guess is that updating the query to not include the
"Chosen" column in filter_horizontal fields would solve this issue
(something like
> > {{{
> > const selectsRelated = document.querySelectorAll(`[data-model-
ref="${modelName}"] div:not(.selector-chosen) > select:not(.admin-
autocomplete)`);
> > }}}
>
> That could work 👍 I'm just wondering though whether there's a better
approach than to continuously blacklist ancestors as we come across these
🤔

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

Django

unread,
Aug 27, 2023, 10:23:35 PM8/27/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------

Comment (by David Sanders):

Replying to [comment:9 yokeshwaran1]:


> I think about a solution which will not continuously blacklisting
ancestors

Yep that's along the lines of what I was getting at 😊👍

The question is though which approach is clearer/easier to maintain. The
benefit of whitelisting is we can remove `not(.admin-autocomplete)` too I
think 🤔

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

Django

unread,
Aug 28, 2023, 4:06:26 AM8/28/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------

Comment (by yokeshwaran1):

Thanks, David. I’ll make the necessary changes and submit a PR with tests
soon.

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

Django

unread,
Sep 8, 2023, 12:21:21 PM9/8/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------

Comment (by yokeshwaran1):

Hi David,
I have opened a PR to address this issue:
https://github.com/django/django/pull/17219
Replying to [comment:11 yokeshwaran1]:


> Thanks, David. I’ll make the necessary changes and submit a PR with
tests soon.

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

Django

unread,
Sep 8, 2023, 1:56:48 PM9/8/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
Reporter: devin13cox | Owner: (none)
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+------------------------------------
Changes (by Natalia Bidart):

* has_patch: 0 => 1


Comment:

Setting the has patch flag.

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

Django

unread,
Sep 11, 2023, 2:56:03 AM9/11/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+----------------------------------------
Reporter: devin13cox | Owner: yokeshwaran1

Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+----------------------------------------
Changes (by Mariusz Felisiak):

* owner: (none) => yokeshwaran1


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

Django

unread,
Sep 14, 2023, 10:28:19 AM9/14/23
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+----------------------------------------
Reporter: devin13cox | Owner: yokeshwaran1
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 1
-------------------------------+----------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:15>

Django

unread,
Feb 21, 2024, 8:18:03 PM2/21/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 1
-------------------------------+--------------------------------------
Changes (by devin13cox):

* owner: yokeshwaran1 => devin13cox

Comment:

Opened new PR on this https://github.com/django/django/pull/17897. Ran
into small issue that still needs work, as described in the old PR. Will
get it patched soon, but if anyone has direction on it I would appreciate
feedback. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:16>

Django

unread,
Feb 27, 2024, 9:03:07 PM2/27/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+--------------------------------------
Changes (by devin13cox):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:17>

Django

unread,
Mar 13, 2024, 5:12:25 PM3/13/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+--------------------------------------
Comment (by devin13cox):

Hello, just wanted to check in and see if there is anything else I need to
do pending a review for this ticket. No rush on getting this in, I just
wanted to make sure you guys aren't waiting on something from me. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:18>

Django

unread,
Mar 13, 2024, 6:23:33 PM3/13/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------+--------------------------------------
Comment (by Tim Graham):

No, the ticket flags are set correctly to put the ticket in the patch
review queue. You can confirm this by looking at the yellow box below the
ticket description ("According to the ticket's flags...").
--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:19>

Django

unread,
Mar 18, 2024, 6:36:17 PM3/18/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 1
-------------------------------+--------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1
* version: 4.2 => dev

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:20>

Django

unread,
Mar 26, 2024, 9:02:27 AM3/26/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------+--------------------------------------
Changes (by Natalia Bidart):

* easy: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:21>

Django

unread,
Apr 12, 2024, 2:50:51 PM4/12/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
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: 1
-------------------------------+--------------------------------------
Changes (by devin13cox):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:22>

Django

unread,
May 8, 2024, 7:33:15 AM5/8/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:23>

Django

unread,
Jun 6, 2024, 6:18:22 PM6/6/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------+--------------------------------------
Reporter: devin13cox | Owner: devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
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: 1
-------------------------------+--------------------------------------
Changes (by devin13cox):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:24>

Django

unread,
Jun 12, 2024, 5:41:33 AM6/12/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------------+-------------------------------------
Reporter: devin13cox | Owner:
| devin13cox
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
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: 1
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:25>

Django

unread,
Jun 12, 2024, 7:09:22 AM6/12/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------------+-------------------------------------
Reporter: devin13cox | Owner:
| devin13cox
Type: Bug | Status: closed
Component: contrib.admin | Version: dev
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: 1
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

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

Comment:

In [changeset:"719a42b589d7551fc84708044b9e984ce723c8a2" 719a42b5]:
{{{#!CommitTicketReference repository=""
revision="719a42b589d7551fc84708044b9e984ce723c8a2"
Fixed #34789 -- Prevented updateRelatedSelectsOptions from
adding entries to filter_horizontal chosen box.

Co-authored-by: yokeshwaran1 <yoke...@yahoo.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:26>

Django

unread,
Jun 14, 2024, 8:22:33 AM6/14/24
to django-...@googlegroups.com
#34789: `filter_horizontal` duplicates entries in "Chosen" column after instance is
added via in another field using the "plus" JS action
-------------------------------------+-------------------------------------
Reporter: devin13cox | Owner:
| devin13cox
Type: Bug | Status: closed
Component: contrib.admin | Version: dev
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: 1
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"49a3a8d9a22ebcb29fdc4bacaa204f0bd2a6abf6" 49a3a8d]:
{{{#!CommitTicketReference repository=""
revision="49a3a8d9a22ebcb29fdc4bacaa204f0bd2a6abf6"
[5.1.x] Fixed #34789 -- Prevented updateRelatedSelectsOptions from
adding entries to filter_horizontal chosen box.

Co-authored-by: yokeshwaran1 <yoke...@yahoo.com>

Backport of 719a42b589d7551fc84708044b9e984ce723c8a2 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:27>
Reply all
Reply to author
Forward
0 new messages