Skip to content
Merged
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
2 changes: 1 addition & 1 deletion django/db/models/sql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ def get_distinct(self):
opts = self.query.get_meta()

for name in self.query.distinct_fields:
parts = name.split(LOOKUP_SEP)
parts = self.query.get_names_to_join(name)
_, targets, alias, joins, path, _, transform_function = self._setup_joins(
parts, opts, None
)
Expand Down
10 changes: 7 additions & 3 deletions django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,10 +1487,14 @@ def try_transform(self, lhs, name, lookups=None):

def get_names_to_join(self, expr):
"""
Helper method for the resolution of expressions that could either be a
FilteredRelation alias or a field lookup.
Helper method for the resolution of expressions that could either be an
annotation alias (including FilteredRelation) or a field lookup.
"""
return [expr] if expr in self._filtered_relations else expr.split(LOOKUP_SEP)
return (
[expr]
if (expr in self._filtered_relations or expr in self.annotations)
else expr.split(LOOKUP_SEP)
)

def build_filter(
self,
Expand Down
3 changes: 0 additions & 3 deletions docs/howto/custom-model-fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,6 @@ This assumes we've imported a ``MyFormField`` field class (which has its own
default widget). This document doesn't cover the details of writing custom form
fields.

.. _helper functions: ../forms/#generating-forms-for-models
.. _forms documentation: ../forms/

.. _emulating-built-in-field-types:

Emulating built-in field types
Expand Down
2 changes: 0 additions & 2 deletions docs/ref/contrib/sitemaps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ Here's an example of a :doc:`URLconf </topics/http/urls>` using
),
]

.. _URLconf: ../url_dispatch/

Sitemap for static views
========================

Expand Down
1 change: 0 additions & 1 deletion docs/ref/templates/language.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ or Jinja2_, you should feel right at home with Django's templates.
extensions </howto/custom-template-tags>` to the template language as
needed).

.. _`The Django template language: For Python programmers`: ../templates_python/
.. _Smarty: https://www.smarty.net/
.. _Jinja2: https://palletsprojects.com/p/jinja/

Expand Down
5 changes: 0 additions & 5 deletions docs/topics/i18n/translation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2170,11 +2170,6 @@ Note that, with static (middleware-less) translation, the language is in
``settings.LANGUAGE_CODE``, while with dynamic (middleware) translation, it's
in ``request.LANGUAGE_CODE``.

.. _settings file: ../settings/
.. _middleware documentation: ../middleware/
.. _session: ../sessions/
.. _request object: ../request_response/#httprequest-objects

.. _how-django-discovers-translations:

How Django discovers translations
Expand Down
2 changes: 0 additions & 2 deletions docs/topics/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ Use the ``--settings`` command-line argument to specify the settings manually:

django-admin runserver --settings=mysite.settings

.. _django-admin: ../django-admin/

On the server (``mod_wsgi``)
----------------------------

Expand Down
8 changes: 4 additions & 4 deletions tests/backends/oracle/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def patch_execute_statements(self, execute_statements):
)

@mock.patch.object(DatabaseCreation, "_test_user_create", return_value=False)
@unittest.skipUnless(
os.environ.get("TESTPILOT_USER") is not None,
@unittest.skipIf(
os.environ.get("TESTPILOT_USERNAME") is not None,
"Not possible with Oracle Test Pilot",
)
def test_create_test_db(self, *mocked_objects):
Expand All @@ -67,8 +67,8 @@ def test_create_test_db(self, *mocked_objects):
creation._create_test_db(verbosity=0, keepdb=True)

@mock.patch.object(DatabaseCreation, "_test_database_create", return_value=False)
@unittest.skipUnless(
os.environ.get("TESTPILOT_USER") is not None,
@unittest.skipIf(
os.environ.get("TESTPILOT_USERNAME") is not None,
"Not possible with Oracle Test Pilot",
)
def test_create_test_user(self, *mocked_objects):
Expand Down
8 changes: 7 additions & 1 deletion tests/distinct_on_fields/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import connection
from django.db.models import CharField, F, FloatField, Max
from django.db.models import CharField, F, FloatField, Max, Value
from django.db.models.expressions import RawSQL
from django.db.models.functions import Lower
from django.test import TestCase, skipUnlessDBFeature
Expand Down Expand Up @@ -312,3 +312,9 @@ def test_disallowed_update_distinct_on(self):
msg = "Cannot call update() after .distinct(*fields)."
with self.assertRaisesMessage(TypeError, msg):
qs.update(name="p4")

def test_distinct_on_annotation_alias_with_lookup_separator(self):
celebrities = Celebrity.objects.annotate(
celebrity__something=Value(1)
).distinct("celebrity__something")
self.assertEqual(len(celebrities), 1)
Loading