Field.primary_key documentation should details its interaction with CompositePrimaryKey
A particular focus should be put on the fact that the flag will and should only be set to True
if the field is the single member of the primary key. When a composite primary is defined on the model this flag will be False
for all the fields defined on the model and _meta.pk_fields
(which should be documented) should be used instead to build composite primary key ready third-party application.
In other words, it should be made clear that code that relies solely on Field.primary_key
is not composite primary key ready and that _meta.pk_fields
should be used instead. I feel like this is something that should be clearly pointed out in the composite primary key documentation on how to make reusable app code composite primary key ready.
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Severity: |
Normal → Release blocker
|
Triage Stage: |
Unreviewed → Accepted
|
Cc: |
Csirmaz Bendegúz added
|
Owner: |
set to Simon Charette
|
Status: |
new → assigned
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
From #36074
I am not sure how best to reword the title but I think this piece of work (checking the existing checks against the
primary_key
attribute and whether they should be using field in opts.pk_fields, as well as checking the decision to not setting this flag to True when included as a member of CompositePrimaryKey) could be part of this ticket, as this documentation should accompany those changes.