[Django] #27944: Have meta.get_field('pk') return the primary key field directly

30 views
Skip to first unread message

Django

unread,
Mar 15, 2017, 5:20:16 PM3/15/17
to django-...@googlegroups.com
#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.

Django

unread,
Mar 15, 2017, 9:14:32 PM3/15/17
to django-...@googlegroups.com
#27944: Have meta.get_field('pk') return the primary key field directly
-------------------------------------+-------------------------------------

Reporter: Josh Schneier | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27944#comment:1>

Django

unread,
Mar 16, 2017, 11:41:40 AM3/16/17
to django-...@googlegroups.com
#27944: Have meta.get_field('pk') return the primary key field directly
-------------------------------------+-------------------------------------
Reporter: Josh Schneier | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Josh Schneier):

* owner: nobody => Josh Schneier
* status: new => assigned
* has_patch: 0 => 1


Comment:

Patch here: https://github.com/django/django/pull/8191

--
Ticket URL: <https://code.djangoproject.com/ticket/27944#comment:2>

Django

unread,
Mar 16, 2017, 12:47:04 PM3/16/17
to django-...@googlegroups.com
#27944: Have meta.get_field('pk') return the primary key field directly
-------------------------------------+-------------------------------------
Reporter: Josh Schneier | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27944#comment:3>

Django

unread,
Mar 16, 2017, 2:00:48 PM3/16/17
to django-...@googlegroups.com
#27944: Have meta.get_field('pk') return the primary key field directly
-------------------------------------+-------------------------------------
Reporter: Josh Schneier | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Josh Schneier):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27944#comment:4>

Django

unread,
Jul 27, 2017, 10:27:17 AM7/27/17
to django-...@googlegroups.com
#27944: Have meta.get_field('pk') return the primary key field directly
-------------------------------------+-------------------------------------
Reporter: Josh Schneier | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Someday/Maybe


Comment:

The discussion on the PR suggests that a DevelopersMailingList discussion
is needed to see if there's consensus to proceed with this.

--
Ticket URL: <https://code.djangoproject.com/ticket/27944#comment:5>

Django

unread,
Aug 23, 2022, 12:58:00 PM8/23/22
to django-...@googlegroups.com
#27944: Have meta.get_field('pk') return the primary key field directly
-------------------------------------+-------------------------------------
Reporter: Josh Schneier | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: assigned => closed
* resolution: => wontfix


Comment:

I think this can be closed as ''wontfix'' given the discussion on the
mailing list didn't reach consensus around the backward compatibility
risks.

--
Ticket URL: <https://code.djangoproject.com/ticket/27944#comment:6>

Reply all
Reply to author
Forward
0 new messages