[Django] #36759: Fixed variable shadowing in ValidationError.__init__()

7 views
Skip to first unread message

Django

unread,
Nov 30, 2025, 9:20:27 PM (2 days ago) Nov 30
to django-...@googlegroups.com
#36759: Fixed variable shadowing in ValidationError.__init__()
-------------------------------------+-------------------------------------
Reporter: Mohit Sharma | Type: Bug
Status: new | Component: Core
| (Other)
Version: dev | Severity: Normal
Keywords: variable-shadowing | Triage Stage:
ValidationError exceptions | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
== Problem ==
The `ValidationError.__init__()` method has a variable shadowing bug in
the list processing branch. The loop variable `message` shadows the
function parameter `message`, which can cause issues when processing lists
of validation errors.

== Location ==
`django/core/exceptions.py`, line 175

== Current Code ==
for message in message: # Variable shadowing!== Solution ==
Rename the loop variable from `message` to `item` to avoid shadowing the
function parameter.

== Patch ==
I have a patch ready with:
- Fix: Renamed loop variable to `item`
- Test: Added comprehensive test `test_list_input_processes_all_items()`
- All existing tests pass

== Branch ==
Branch: ticket_12345
PR: [Will add PR link after creating]


== Solution ==
Rename the loop variable from message to item to avoid shadowing the
function parameter.
== Patch ==
I have a patch ready with:
Fix: Renamed loop variable to item
Test: Added comprehensive test test_list_input_processes_all_items()
All existing tests pass
== Branch ==
Branch: ticket_12345
PR: [Will add PR link after creating]
--
Ticket URL: <https://code.djangoproject.com/ticket/36759>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 30, 2025, 9:30:31 PM (2 days ago) Nov 30
to django-...@googlegroups.com
#36759: Fixed variable shadowing in ValidationError.__init__()
-------------------------------------+-------------------------------------
Reporter: Mohit Sharma | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: variable-shadowing | Triage Stage:
ValidationError exceptions | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mohit Sharma):

Pull request created: https://github.com/django/django/pull/20347
--
Ticket URL: <https://code.djangoproject.com/ticket/36759#comment:1>

Django

unread,
Dec 1, 2025, 8:43:54 AM (2 days ago) Dec 1
to django-...@googlegroups.com
#36759: Fixed variable shadowing in ValidationError.__init__()
-------------------------------------+-------------------------------------
Reporter: Mohit Sharma | Owner: (none)
Type: Bug | Status: closed
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: invalid
Keywords: variable-shadowing | Triage Stage:
ValidationError exceptions | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* resolution: => invalid
* status: new => closed

Comment:

Thanks for the ticket, however, we try to avoid trivial refactoring as it
creates unnecessary noise in the history. Variable shadowing doesn't cause
any issue in this method.
--
Ticket URL: <https://code.djangoproject.com/ticket/36759#comment:2>
Reply all
Reply to author
Forward
0 new messages