Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#22570 closed Cleanup/optimization (fixed)

Form.__getitem__ KeyError should be more descriptive

Reported by: Ben Davis Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

When you try to access a nonexistent key on a Form, it raises this exception:

raise KeyError('Key %r not found in Form' % name)

This is vague in situations where you have multiple forms. You have to do a more digging to find out which form it is. It should be:

raise KeyError("Key %r not found in '%s'" % (name, self.__class__.__name__))

Change History (4)

comment:1 Changed 2 years ago by Ben Davis

Has patch: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 2 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Test needs updating to pass on Python 3.

comment:3 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In df60db0e7872796b4a48e62e9733f85c8ddf8306:

Fixed #22570 -- Made Form.getitem KeyError more descriptive.

comment:4 Changed 2 years ago by Tim Graham <timograham@…>

In 549b65824184711823e6a8c38ccf7365f10023d8:

[1.7.x] Fixed #22570 -- Made Form.getitem KeyError more descriptive.

Backport of df60db0e78 from master

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