Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31190 closed Bug (fixed)

prefetch_related() crashes for GenericForeignKey with custom related object ID.

Reported by: Eugene Hatsko Owned by: Eugene Hatsko
Component: contrib.contenttypes Version: 3.0
Severity: Release blocker Keywords: GenericRelatedObjectManager
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On generic foreign key definition like:

obj = GenericForeignKey('object_content_type', 'object_id')

and

some_instances = GenericRelation('some_app.SomeModel', object_id_field='object_id', content_type_field='object_content_type')

On trying to get all some_instances, we get the next error:

AttributeError: 'SomeModel' object has no attribute 'content_type_id'

Attachments (1)

test-31190.diff (1.0 KB ) - added by Mariusz Felisiak 4 years ago.
Regression test.

Download all attachments as: .zip

Change History (5)

comment:1 by Mariusz Felisiak, 4 years ago

Needs documentation: set
Severity: NormalRelease blocker
Summary: AttributeError: "GenericRelatedObjectManager" has hardcoded 'content_type_id'AttributeError: "GenericRelatedObjectManager" has hardcoded 'content_type_id'.
Triage Stage: UnreviewedAccepted

Thanks for this report.

Regression in dffa3e1992562ba60512d96d1eb5859ffff2ceb5.

Reproduced at e4bc4f26b27122f5887a5eea811ff985d9ab8b8d.

by Mariusz Felisiak, 4 years ago

Attachment: test-31190.diff added

Regression test.

comment:2 by Mariusz Felisiak, 4 years ago

Summary: AttributeError: "GenericRelatedObjectManager" has hardcoded 'content_type_id'.prefetch_related() crashes for GenericForeignKey with custom related object ID.

comment:3 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 0b013564:

Fixed #31190 -- Fixed prefetch_related() crash for GenericForeignKey with custom ContentType foreign key.

Regression in dffa3e1992562ba60512d96d1eb5859ffff2ceb5.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In a56e45a2:

[3.0.x] Fixed #31190 -- Fixed prefetch_related() crash for GenericForeignKey with custom ContentType foreign key.

Regression in dffa3e1992562ba60512d96d1eb5859ffff2ceb5.

Backport of 0b013564ef0609d95b1d263626f2e15bccda1a50 from master

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