#13085 closed Bug (fixed)
GenericForeignKey.get_content_type fails if `object` or `id` evaluate to False. Should use 'is not None' test.
Reported by: | Ben | Owned by: | |
---|---|---|---|
Component: | contrib.contenttypes | 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
contenttypes.GenericForeignKey.get_content_type
is used to find the content type of an object. If the object evaluates to False, then an error is raised. This is because 'if obj:' is used, rather than 'if obj is not None:'. The same problem exists for the 'id' argument, and I believe also in the __get__
method.
Attachments (2)
Change History (14)
by , 15 years ago
Attachment: | generic.py.diff added |
---|
comment:1 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
Owner: | changed from | to
---|
comment:3 by , 15 years ago
Needs tests: | unset |
---|
I've included a new patch with a regression test included. The object will be false if it has nonzero is defined and returns False, or if len is defined and returns 0. Either of these should be possible without generic objects failing. The bug would also cause problems if a generic object was used with content_type_id=0.
comment:4 by , 14 years ago
Component: | Contrib apps → contrib.contenttypes |
---|
comment:5 by , 14 years ago
Type: | → Bug |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|
comment:7 by , 13 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
UI/UX: | unset |
Patch no longer cleanly applies to trunk.
comment:8 by , 13 years ago
Owner: | removed |
---|
comment:11 by , 12 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Two quick points:
Accepting because I think I can spot the problem case (getting the content type for an unsaved object)