Opened 9 months ago

Closed 9 months ago

Last modified 9 months 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 9 months ago.
Regression test.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 months ago by Mariusz Felisiak

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.

Changed 9 months ago by Mariusz Felisiak

Attachment: test-31190.diff added

Regression test.

comment:2 Changed 9 months ago by Mariusz Felisiak

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

comment:3 Changed 9 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 0b013564:

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

Regression in dffa3e1992562ba60512d96d1eb5859ffff2ceb5.

comment:4 Changed 9 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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