Skip to content

Conversation

jacobtylerwalls
Copy link
Member

Trac ticket number

ticket-36648

Branch description

Before, .first() and .last() checked if the primary key was already in the group by for an aggregation, otherwise it threw a TypeError. (See ticket-33772).

Now, if you have a composite primary key, you can also provide each column individually in a values() call instead of needing to use the "pk" syntax.

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

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@nessita nessita self-requested a review October 14, 2025 17:16
Copy link
Contributor

@nessita nessita left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! 🌟

I added some optional suggestions for your evaluation.

@jacobtylerwalls jacobtylerwalls changed the title Fixed #36648, Refs #33772 -- Accounted for specifying pk fields individually in first()/last() when aggregating. Fixed #36648, Refs #33772 -- Accounted for composite pks in first()/last() when aggregating. Oct 14, 2025
@jacobtylerwalls jacobtylerwalls merged commit 02eed4f into django:main Oct 14, 2025
45 of 49 checks passed
@jacobtylerwalls jacobtylerwalls deleted the jtw/first-pk-exception branch October 14, 2025 19:48
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