[Django] #23816: Ability to defer model field by default

36 views
Skip to first unread message

Django

unread,
Nov 13, 2014, 1:20:05 PM11/13/14
to django-...@googlegroups.com
#23816: Ability to defer model field by default
----------------------------------------------+--------------------
Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Today's small #IWantAPony is to be able to mark model fields as deferred
by default. No need to chase down every queryset and add `.defer()`, or
use a custom manager setup & remember to set `use_for_related_fields`.

{{{
class MyModel(models.Model):
enormous_field = models.TextField(defer=True)
other_field = models.IntegerField()
}}}

Which is (simplistically) equivalent to the following:

{{{
class MyManager(models.Manager):
use_for_related_fields = True

def get_queryset(self, *args, **kwargs):
return super(MyManager, self).get_queryset(*args,
**kwargs).defer("enormous_field")

class MyModel(models.Model):
enormous_field = models.TextField()
other_field = models.IntegerField()

objects = MyManager()
}}}

Obviously, you can still do `MyModel.objects.defer(None)` to do the full
query.

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

Django

unread,
Nov 14, 2014, 3:06:17 PM11/14/14
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I find this really useful, as most of the times you (myself actually,
assuming most people too) really don't make a manager just for this
optimisation. So defining deferred fields at model level makes sense for
me. Though I would prefer to specify the fields in the model's Meta
options, as a list of field names, similar to unique_together option.

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

Django

unread,
Nov 14, 2014, 3:07:22 PM11/14/14
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* cc: akiskesoglou@… (added)


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

Django

unread,
Nov 21, 2014, 2:45:10 PM11/21/14
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

I am a little hesitant to accept since there is already a way to
accomplish this, but tentatively accepting so we can see what a patch
looks like and someone else really like the idea.

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

Django

unread,
Nov 21, 2014, 2:51:54 PM11/21/14
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by carljm):

I'm also hesitant about adding something that's already doable via a
custom manager; I'm probably -0.

If we do it, it should definitely be a `Meta` option, not a field arg,
IMO. It applies to fields, but it's really a characteristic of querying on
the model class, not inherently of the Field.

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

Django

unread,
Nov 21, 2014, 3:04:03 PM11/21/14
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by dfunckt):

I'm inclined to have a go at this. Here's how I envision it:

{{{
class Post(models.Model):
body_text = models.TextField()
body_html = models.TextField(blank=True)

class Meta:
initially_deferred_fields = ('body_text', 'body_html')
}}}


Some thoughts:

- Not sure about the name of the meta attribute, it requires almost as
much effort to get the spelling right as creating a custom manager, but
I'd like to avoid naming it `defer` or `deferred_fields`. I'd like input
on this, but it's not pressing.
- The patch author should be aware of the model meta refactor, perhaps
beginning work after it lands?

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

Django

unread,
Feb 22, 2016, 4:55:14 AM2/22/16
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
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
-------------------------------------+-------------------------------------

Comment (by willstott101):

I can see a use for this. Currently using a manager which looks at
`auto_defer` (on the manager due to
[https://code.djangoproject.com/ticket/5793 5793]).

{{{
class AutoDeferManagerMixin(object):
use_for_related_fields = True
auto_defer = tuple()

def get_queryset(self, *args, **kwargs):
return super(AutoDeferManagerMixin, self).get_queryset(*args,
**kwargs).defer(*self.auto_defer)
}}}

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

Django

unread,
Oct 11, 2017, 6:03:25 AM10/11/17
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner:
| Denis.Tarykin
Type: New feature | Status: assigned

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 Denis.Tarykin):

* status: new => assigned
* owner: nobody => Denis.Tarykin


--
Ticket URL: <https://code.djangoproject.com/ticket/23816#comment:7>

Django

unread,
Nov 3, 2017, 6:17:54 AM11/3/17
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner:
| Denis.Tarykin
Type: New feature | 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 Denis.Tarykin):

* has_patch: 0 => 1


Comment:

PR - https://github.com/django/django/pull/9309

--
Ticket URL: <https://code.djangoproject.com/ticket/23816#comment:8>

Django

unread,
Jan 31, 2018, 4:31:04 AM1/31/18
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner:
| Denis.Tarykin
Type: New feature | 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 Carlton Gibson):

* needs_better_patch: 0 => 1


Comment:

Marking "Patch needs improvement" pending comments on PR

--
Ticket URL: <https://code.djangoproject.com/ticket/23816#comment:9>

Django

unread,
Jun 25, 2021, 6:37:40 AM6/25/21
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner:
| Denis.Tarykin
Type: New feature | Status: assigned
Component: Database layer | Version: dev

(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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

#24096 was a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/23816#comment:10>

Django

unread,
Nov 24, 2021, 4:03:25 AM11/24/21
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner:
| Denis.Tarykin
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(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 Carlos Palol):

* cc: Carlos Palol (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/23816#comment:11>

Django

unread,
Jan 17, 2022, 7:04:56 AMJan 17
to django-...@googlegroups.com
#23816: Ability to defer model field by default
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner:
| Denis.Tarykin
Type: New feature | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed

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

* status: assigned => closed
* resolution: => wontfix
* stage: Accepted => Unreviewed


Comment:

This ticket was tentatively accepted and we have several opinions against
its implementation ([https://code.djangoproject.com/ticket/23816#comment:4
Carl],
[https://github.com/django/django/pull/14110#pullrequestreview-610972680
Simon],
[https://github.com/django/django/pull/14110#issuecomment-830777943 Adam],
we can add me to this list).

Marking as "wontfix", because it seems we need to reach a consensus on the
DevelopersMailingList before moving forward. Please
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets follow the triaging guidelines with regards to
wontfix tickets] and take this to DevelopersMailingList to reach a wider
audience and see what other think.

--
Ticket URL: <https://code.djangoproject.com/ticket/23816#comment:12>

Reply all
Reply to author
Forward
0 new messages