Skip to content

Conversation

adamchainz
Copy link
Member

Trac ticket number

ticket-28586

Branch description

To support field fetching modes for GenericForeignKey, it needs to conform to a new "fetcher protocol", which includes having a field attribute that points from the "fetcher" to the actual field.

The core related fields, like ForeignKey, all use descriptors with a field attribute. These descriptors then act as their "fetcher" class.

GenericForeignKey has always been a bit odd because it does not have a separate descriptor class. This PR removes that oddity by adding such a class and moving the appropriate methods there.

This change follows ticket-35224, which made GenericForeignKey an actual field class.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #17886 attempts to remove this check function, though I haven't managed to get that into a mergeable state yet.

@adamchainz adamchainz force-pushed the ticket_28586_gfk_descriptor branch from 0eaca3b to 28b6b1f Compare April 17, 2025 09:24
@adamchainz adamchainz force-pushed the ticket_28586_gfk_descriptor branch from 28b6b1f to 7a61735 Compare April 29, 2025 22:41
@adamchainz adamchainz force-pushed the ticket_28586_gfk_descriptor branch 4 times, most recently from 600a157 to f5d8c48 Compare September 4, 2025 16:42
@adamchainz adamchainz force-pushed the ticket_28586_gfk_descriptor branch 3 times, most recently from 5af844a to bc2e3f2 Compare September 17, 2025 10:03
This makes GenericForeignKey more similar to other fields which act as
descriptors, preparing it to add “fetcher protocol” support in a clear and
consistent way.
@jacobtylerwalls jacobtylerwalls force-pushed the ticket_28586_gfk_descriptor branch from bc2e3f2 to d79d1f7 Compare September 18, 2025 22:37
@jacobtylerwalls jacobtylerwalls merged commit 74a9c27 into django:main Sep 18, 2025
47 checks passed
@adamchainz adamchainz deleted the ticket_28586_gfk_descriptor branch September 20, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants