[Django] #32587: Use RelatedManager of parent object in get_queryset of inlines

17 views
Skip to first unread message

Django

unread,
Mar 23, 2021, 2:21:38 PM3/23/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines
-------------------------------------------+------------------------
Reporter: Andreas Galazis | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------------+------------------------
This would help support prefetching configuration on parent admin's
queryset.

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

Django

unread,
Mar 23, 2021, 2:26:32 PM3/23/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

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

* keywords: => admin, prefetch, inline
* component: Uncategorized => contrib.admin


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

Django

unread,
Mar 24, 2021, 6:14:01 AM3/24/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

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

* type: Uncategorized => Cleanup/optimization


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

Django

unread,
Mar 24, 2021, 8:08:43 AM3/24/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prfetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Andreas Galazis:

Old description:

> This would help support prefetching configuration on parent admin's
> queryset.

New description:

This would help support prefetching configuration on parent admin's
queryset.

This is not sufficient to support prefetching since there are multiple (I
have found at least 3) instances in inline admin ans inline formset where
self.get_queryset()[i] paradigm is used.

At least perform some code cleanup?

Even if this issue a won't fix for any reason at least abstract fetching
instance by in index in a `ge_instance_by_index` method so that we can
implement admins that do what we want of top of current base classes. If
this is done then we will be able to overwrite ge_instance_by_index to
return `list(self.get_queryset())[i]`
instead of `self.get_queryset()[i]` on inlines that support prefetching

--

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

Django

unread,
Mar 24, 2021, 8:10:39 AM3/24/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prfetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Andreas Galazis:

Old description:

> This would help support prefetching configuration on parent admin's
> queryset.


> This is not sufficient to support prefetching since there are multiple (I
> have found at least 3) instances in inline admin ans inline formset where
> self.get_queryset()[i] paradigm is used.
>
> At least perform some code cleanup?
>
> Even if this issue a won't fix for any reason at least abstract fetching
> instance by in index in a `ge_instance_by_index` method so that we can
> implement admins that do what we want of top of current base classes. If
> this is done then we will be able to overwrite ge_instance_by_index to
> return `list(self.get_queryset())[i]`
> instead of `self.get_queryset()[i]` on inlines that support prefetching

New description:

This would help support prefetching configuration on parent admin's
queryset.

This is not sufficient to support prefetching since there are multiple (I

have found at least 3) instances in inline admin and inline formset where


`self.get_queryset()[i]` paradigm is used.

At least perform some code cleanup?

Even if this issue a won't fix for any reason at least abstract fetching
instance by in index in a `ge_instance_by_index` method so that we can
implement admins that do what we want of top of current base classes. If
this is done then we will be able to overwrite ge_instance_by_index to
return `list(self.get_queryset())[i]` instead of
`self.get_queryset()[i]` on inlines that support prefetching

--

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

Django

unread,
Mar 24, 2021, 8:27:31 AM3/24/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prfetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Andreas Galazis:

Old description:

> This would help support prefetching configuration on parent admin's
> queryset.


> This is not sufficient to support prefetching since there are multiple (I
> have found at least 3) instances in inline admin and inline formset where
> `self.get_queryset()[i]` paradigm is used.
>
> At least perform some code cleanup?
>
> Even if this issue a won't fix for any reason at least abstract fetching
> instance by in index in a `ge_instance_by_index` method so that we can
> implement admins that do what we want of top of current base classes. If
> this is done then we will be able to overwrite ge_instance_by_index to
> return `list(self.get_queryset())[i]` instead of
> `self.get_queryset()[i]` on inlines that support prefetching

New description:

This would help support prefetching configuration on parent admin's
queryset.

This is not sufficient to support prefetching since there are multiple (I
have found at least 3) instances in inline admin and inline formset where
`self.get_queryset()[i]` paradigm is used.

At least perform some code cleanup?

Even if this issue a won't fix for any reason at least abstract fetching
instance by in index in a `ge_instance_by_index` method so that we can
implement admins that do what we want of top of current base classes. If
this is done then we will be able to overwrite ge_instance_by_index to
return `list(self.get_queryset())[i]` instead of
`self.get_queryset()[i]` on inlines that support prefetching

Also I believe that the logic about preparing queryset in
BaseInlineFormSet should exist in a separate function called
`prepare_queryset`:


{{{
def prepare_queryset(queryset):
if queryset is None:
queryset = self.model._default_manager
if self.instance.pk is not None:
qs = queryset.filter(**{self.fk.name: self.instance})
else:
qs = queryset.none()
return qs
}}}
instead if throwing it `__init__` Intit could just call the above to get
the value . This way filtering wouldn't be enforced in the case of related
manager querysets since we could overwrite the method.

--

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

Django

unread,
Mar 24, 2021, 8:28:45 AM3/24/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prefetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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

Django

unread,
Mar 24, 2021, 8:31:25 AM3/24/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prefetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Andreas Galazis:

Old description:

> This would help support prefetching configuration on parent admin's
> queryset.


> This is not sufficient to support prefetching since there are multiple (I
> have found at least 3) instances in inline admin and inline formset where
> `self.get_queryset()[i]` paradigm is used.
>
> At least perform some code cleanup?
>
> Even if this issue a won't fix for any reason at least abstract fetching
> instance by in index in a `ge_instance_by_index` method so that we can
> implement admins that do what we want of top of current base classes. If
> this is done then we will be able to overwrite ge_instance_by_index to
> return `list(self.get_queryset())[i]` instead of
> `self.get_queryset()[i]` on inlines that support prefetching
>
> Also I believe that the logic about preparing queryset in
> BaseInlineFormSet should exist in a separate function called
> `prepare_queryset`:
>

> {{{
> def prepare_queryset(queryset):
> if queryset is None:
> queryset = self.model._default_manager
> if self.instance.pk is not None:
> qs = queryset.filter(**{self.fk.name: self.instance})
> else:
> qs = queryset.none()
> return qs
> }}}
> instead if throwing it `__init__` Intit could just call the above to get
> the value . This way filtering wouldn't be enforced in the case of
> related manager querysets since we could overwrite the method.

New description:

This would help support prefetching configuration on parent admin's
queryset.

This is not sufficient to support prefetching since there are multiple (I
have found at least 3) instances in inline admin and inline formset where
`self.get_queryset()[i]` paradigm is used.

At least perform some code cleanup?

Even if this issue a won't fix for any reason at least abstract fetching
instance by in index in a `ge_instance_by_index` method so that we can
implement admins that do what we want of top of current base classes. If
this is done then we will be able to overwrite ge_instance_by_index to
return `list(self.get_queryset())[i]` instead of
`self.get_queryset()[i]` on inlines that support prefetching

Also I believe that the logic about preparing queryset in
BaseInlineFormSet should exist in a separate function called
`prepare_queryset`:


{{{
def prepare_queryset(queryset):
if queryset is None:
queryset = self.model._default_manager
if self.instance.pk is not None:
qs = queryset.filter(**{self.fk.name: self.instance})
else:
qs = queryset.none()
return qs
}}}

instead if throwing it `__init__`. Init could just call the above to get


the value . This way filtering wouldn't be enforced in the case of related
manager querysets since we could overwrite the method.

--

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

Django

unread,
Mar 25, 2021, 3:13:39 AM3/25/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prefetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

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

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


Comment:

The non-reuse of prefetched relationship for inlines is tracked in #18597.

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

Django

unread,
Mar 25, 2021, 4:07:36 AM3/25/21
to django-...@googlegroups.com
#32587: Use RelatedManager of parent object in get_queryset of inlines and support
prefetching
-------------------------------------+-------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: duplicate
Keywords: admin, prefetch, | Triage Stage:
inline | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Andreas Galazis):

Yes but that issue doesn't mention other areas that need refactoring.
Either way I will move my concerns to that issue...

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

Reply all
Reply to author
Forward
0 new messages