Re: [Django] #37310: MediaAsset instances with attributes should not compare equal to strings

1 view
Skip to first unread message

Django

unread,
Sep 2, 2026, 6:33:46 AM (yesterday) Sep 2
to django-...@googlegroups.com
#37310: MediaAsset instances with attributes should not compare equal to strings
-------------------------------------+-------------------------------------
Reporter: miladkhoshdel | Owner:
| miladkhoshdel
Type: Bug | Status: assigned
Component: Forms | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: MediaAsset hash | Triage Stage: Accepted
equality |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by miladkhoshdel):

Thanks, that makes sense. The failing assertions currently rely on this
comparison:

{{{
Stylesheet("a.css", media="screen") == "a.css"
}}}

This is currently `True`, even though `_css_lists` contains a `Stylesheet`
instance rather than a string. With the proposed change, it becomes
`False`, so the expected value should use the normalized object:

{{{
{"screen": [Stylesheet("a.css", media="screen")]}
}}}

The functional change is the intended one: assets with attributes no
longer compare equal to plain strings. Regular media merging and rendering
remain unchanged because ordinary string paths are normalized into
`Script` or `Stylesheet` instances before merging.

After updating these assertions, the full Forms test suite passes. I’ll
revise the patch accordingly and reopen the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/37310#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 2, 2026, 7:41:00 AM (yesterday) Sep 2
to django-...@googlegroups.com
#37310: MediaAsset instances with attributes should not compare equal to strings
-------------------------------------+-------------------------------------
Reporter: miladkhoshdel | Owner:
| miladkhoshdel
Type: Bug | Status: assigned
Component: Forms | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: MediaAsset hash | Triage Stage: Accepted
equality |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by miladkhoshdel):

* has_patch: 0 => 1

Comment:

A patch is available at [https://github.com/django/django/pull/21868 PR].

It prevents `MediaAsset` instances with attributes from comparing equal to
strings and updates the affected tests to use normalized `Stylesheet`
instances.
--
Ticket URL: <https://code.djangoproject.com/ticket/37310#comment:9>

Django

unread,
Sep 2, 2026, 8:33:07 AM (yesterday) Sep 2
to django-...@googlegroups.com
#37310: MediaAsset instances with attributes should not compare equal to strings
-------------------------------------+-------------------------------------
Reporter: miladkhoshdel | Owner:
| miladkhoshdel
Type: Bug | Status: assigned
Component: Forms | Version: 6.1
Severity: Normal | Resolution:
Keywords: MediaAsset hash | Triage Stage: Accepted
equality |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* severity: Release blocker => Normal

Comment:

Confirmed that this also doesn't work in 5.2 and 6.0, so is not a
regression introduced in 6.1
--
Ticket URL: <https://code.djangoproject.com/ticket/37310#comment:10>
Reply all
Reply to author
Forward
0 new messages