[Django] #31706: Removed unnecessary getattr() call in FileDescriptor.__get__().

6 views
Skip to first unread message

Django

unread,
Jun 14, 2020, 11:19:56 AM6/14/20
to django-...@googlegroups.com
#31706: Removed unnecessary getattr() call in FileDescriptor.__get__().
-------------------------------------+-------------------------------------
Reporter: Sultan | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
To retrieve a deferred model attributes, the `__get__` method is called
twice. This is because it uses the `getattr()` function, which in turn
causes the `__get__` method to be called again.

To prevent this unnecessary call, we can simply delete it (since at that
moment the instance dict already contains the reloaded value). This
reduces the number of method calls.

--
Ticket URL: <https://code.djangoproject.com/ticket/31706>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 14, 2020, 6:23:47 PM6/14/20
to django-...@googlegroups.com
#31706: Removed unnecessary getattr() call in FileDescriptor.__get__().
-------------------------------------+-------------------------------------
Reporter: Sultan | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Unreviewed => Ready for checkin


Comment:

[https://github.com/django/django/pull/13064 PR]

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

Django

unread,
Jun 15, 2020, 1:27:30 AM6/15/20
to django-...@googlegroups.com
#31706: Removed unnecessary getattr() call in FileDescriptor.__get__().
-------------------------------------+-------------------------------------
Reporter: Sultan | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"6b25d24a5755bb90c037e2afd485668bae8f179e" 6b25d24a]:
{{{
#!CommitTicketReference repository=""
revision="6b25d24a5755bb90c037e2afd485668bae8f179e"
Fixed #31706 -- Removed unnecessary getattr() call in
FileDescriptor.__get__().

refresh_from_db() loads fields values.
}}}

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

Reply all
Reply to author
Forward
0 new messages