Opened 3 weeks ago

Closed 3 weeks ago

#36759 closed Bug (invalid)

Fixed variable shadowing in ValidationError.__init__()

Reported by: Mohit Sharma Owned by:
Component: Core (Other) Version: dev
Severity: Normal Keywords: variable-shadowing ValidationError exceptions
Cc: Mohit Sharma Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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]

Change History (2)

comment:2 by Mariusz Felisiak, 3 weeks ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top