Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22570 closed Cleanup/optimization (fixed)

Form.__getitem__ KeyError should be more descriptive

Reported by: Ben Davis Owned by: nobody
Component: Forms Version: dev
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 by Ben Davis, 10 years ago

Has patch: set

comment:2 by Tim Graham, 10 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Test needs updating to pass on Python 3.

comment:3 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In df60db0e7872796b4a48e62e9733f85c8ddf8306:

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

comment:4 by Tim Graham <timograham@…>, 10 years ago

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