Opened 14 years ago
Closed 12 years ago
#14325 closed Bug (duplicate)
GenericForeignKey fails if assigned to an object which implements the __len__ method
Reported by: | Martin Natano | Owned by: | Martin Natano |
---|---|---|---|
Component: | contrib.contenttypes | Version: | 1.2 |
Severity: | Normal | Keywords: | contenttypes, genericforeignkey |
Cc: | natano@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Supposing you have a model with a GenericForeignKey:
class Example(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() instance = generic.GenericForeignKey()
and a model which implements the __len__
method:
class Table(models.Model) data = models.TextField() def __len__(self): return 0
If you do
t = Table.object.create() e = Example() e.instance = t
you get an error:
Impossible arguments to GFK.get_content_type!
I think this is cause by checking for a logical True value instead of a "not None" comparison.
Attachments (2)
Change History (11)
by , 14 years ago
Attachment: | fix_genericforeignkey_comparison.diff added |
---|
follow-up: 2 comment:1 by , 14 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 14 years ago
Attachment: | fix_genericforeignkey_comparison_and_add_regressiontest.diff added |
---|
comment:3 by , 14 years ago
Needs tests: | unset |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:5 by , 14 years ago
Component: | Contrib apps → contrib.contenttypes |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
Note:
See TracTickets
for help on using tickets.
fix + regressiontest