Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address #16855 - Deprecate depth kwarg on select_related. #488

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions django/db/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
import itertools
import sys
import warnings

from django.core import exceptions
from django.db import connections, router, transaction, IntegrityError
Expand Down Expand Up @@ -698,6 +699,8 @@ def select_related(self, *fields, **kwargs):
If fields are specified, they must be ForeignKey fields and only those
related objects are included in the selection.
"""
if 'depth' in kwargs:
warnings.warn('The keyword argument "depth" has been deprecated. Use field names instead.', DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a PendingDeprecationWarning at this time. (Also a \n would help readability.)

depth = kwargs.pop('depth', 0)
if kwargs:
raise TypeError('Unexpected keyword arguments to select_related: %s'
Expand Down
3 changes: 3 additions & 0 deletions docs/internals/deprecation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ these changes.

* The ``daily_cleanup.py`` script will be removed.

* The ``depth`` keyword argument will be removed from
:meth:`~django.db.models.query.QuerySet.select_related`.

2.0
---

Expand Down
5 changes: 5 additions & 0 deletions docs/ref/models/querysets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ select_related

.. method:: select_related()

.. deprecated:: 1.5
The ``depth`` parameter to ``select_related()`` has been deprecated. You
should replace it with the use of the ``(*fields)`` format instead. See the
:doc:`Django 1.5 release notes</releases/1.5>` for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - the deprecated sphinx directive automatically inserts a "see release notes" link

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wrong that is only for version added - but in this case the release note doesn't add much, if anything.


Returns a ``QuerySet`` that will automatically "follow" foreign-key
relationships, selecting that additional related-object data when it executes
its query. This is a performance booster which results in (sometimes much)
Expand Down
7 changes: 7 additions & 0 deletions docs/releases/1.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,10 @@ The :djadmin:`cleanup` management command has been deprecated and replaced by

The undocumented ``daily_cleanup.py`` script has been deprecated. Use the
:djadmin:`clearsessions` management command instead.

``depth`` keyword argument in ``select_related``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``depth`` keyword argument in
:meth:`~django.db.models.query.QuerySet.select_related` has been deprecated.
You should use field names instead.