Opened 4 years ago

Closed 4 years ago

#20321 closed Cleanup/optimization (fixed)

MergeDict should give key as argument to KeyError

Reported by: mark.harviston@… Owned by: nobody
Component: Utilities Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Normally when a dict raises a KeyError it passes the key to .args[0], but MergeDict does not do this.

to fix simply change raise KeyError to raise KeyError(key) on line 23 of utils/datastructures.py

I'm making a REST-like API that takes input on either POST or GET I wanted to wrap my whole thing in a try...except KeyError, and then give an appropriate error message with the missing field, but unlike request.GET and response.POST which are real dicts, request.REQUEST is a MergeDict and does not pass they key that failed as an argument.

Change History (2)

comment:1 Changed 4 years ago by Claude Paroz

Has patch: unset
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:2 Changed 4 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 4769db6b5fddaed93a8d8d03d0c36f7262e9ac8b:

Fixed #20321 -- Added missing key name in MergeDict KeyError message

Thanks mark.harviston et gmail.com for the report.

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