#27944: Have meta.get_field('pk') return the primary key field directly
------------------------------------------------+------------------------
Reporter: Josh Schneier | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Follow up ticket discussion on this topic:
https://github.com/django/django/pull/8148
While fixing #27897, which is caused by calling `.get_field('pk')`, I ran
across the fact that we are now checking `== 'pk'` before calling
`.get_field` in several places. My proposal is to simply handle this
special case inside of `get_field` directly.
I have a patch but there is a single test regression on
[https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L232-L239|
this system check]. My idea was to change the message and `obj` to
`self.model` but I'm not sure what the backwards compatibility guarantees
are for the message.
Regardless I think we should do this because it will prevent a whole class
of bugs in the future and `'pk'` is already special cased everywhere.
--
Ticket URL: <https://code.djangoproject.com/ticket/27944>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.2e184dc8b3966dcba9fc885bfe9547d8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.