1
0
mirror of https://github.com/django/django.git synced 2025-08-10 11:59:13 +00:00

Refs #16055 -- Removed get_joining_columns()/get_reverse_joining_columns() methods per deprecation timeline.

This commit is contained in:
Sarah Boyce 2024-12-12 17:49:25 +01:00
parent 9a3f86e960
commit 0a0f9b4acc
5 changed files with 21 additions and 120 deletions

View File

@ -1,6 +1,5 @@
import functools import functools
import inspect import inspect
import warnings
from functools import partial from functools import partial
from django import forms from django import forms
@ -14,7 +13,6 @@ from django.db.models.constants import LOOKUP_SEP
from django.db.models.deletion import CASCADE, SET_DEFAULT, SET_NULL from django.db.models.deletion import CASCADE, SET_DEFAULT, SET_NULL
from django.db.models.query_utils import PathInfo from django.db.models.query_utils import PathInfo
from django.db.models.utils import make_model_tuple from django.db.models.utils import make_model_tuple
from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -817,27 +815,6 @@ class ForeignObject(RelatedField):
attname, column = super().get_attname_column() attname, column = super().get_attname_column()
return attname, None return attname, None
def get_joining_columns(self, reverse_join=False):
warnings.warn(
"ForeignObject.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
source = self.reverse_related_fields if reverse_join else self.related_fields
return tuple(
(lhs_field.column, rhs_field.column) for lhs_field, rhs_field in source
)
def get_reverse_joining_columns(self):
warnings.warn(
"ForeignObject.get_reverse_joining_columns() is deprecated. Use "
"get_reverse_joining_fields() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
return self.get_joining_columns(reverse_join=True)
def get_joining_fields(self, reverse_join=False): def get_joining_fields(self, reverse_join=False):
return tuple( return tuple(
self.reverse_related_fields if reverse_join else self.related_fields self.reverse_related_fields if reverse_join else self.related_fields

View File

@ -9,10 +9,7 @@ They also act as reverse fields for the purposes of the Meta API because
they're the closest concept currently available. they're the closest concept currently available.
""" """
import warnings
from django.core import exceptions from django.core import exceptions
from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.hashable import make_hashable from django.utils.hashable import make_hashable
@ -192,15 +189,6 @@ class ForeignObjectRel(FieldCacheMixin):
qs = qs.order_by(*ordering) qs = qs.order_by(*ordering)
return (blank_choice if include_blank else []) + [(x.pk, str(x)) for x in qs] return (blank_choice if include_blank else []) + [(x.pk, str(x)) for x in qs]
def get_joining_columns(self):
warnings.warn(
"ForeignObjectRel.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
return self.field.get_reverse_joining_columns()
def get_joining_fields(self): def get_joining_fields(self):
return self.field.get_reverse_joining_fields() return self.field.get_reverse_joining_fields()

View File

@ -3,11 +3,8 @@ Useful auxiliary data structures for query construction. Not useful outside
the SQL domain. the SQL domain.
""" """
import warnings
from django.core.exceptions import FullResultSet from django.core.exceptions import FullResultSet
from django.db.models.sql.constants import INNER, LOUTER from django.db.models.sql.constants import INNER, LOUTER
from django.utils.deprecation import RemovedInDjango60Warning
class MultiJoin(Exception): class MultiJoin(Exception):
@ -65,20 +62,11 @@ class Join:
self.join_type = join_type self.join_type = join_type
# A list of 2-tuples to use in the ON clause of the JOIN. # A list of 2-tuples to use in the ON clause of the JOIN.
# Each 2-tuple will create one join condition in the ON clause. # Each 2-tuple will create one join condition in the ON clause.
if hasattr(join_field, "get_joining_fields"): self.join_fields = join_field.get_joining_fields()
self.join_fields = join_field.get_joining_fields() self.join_cols = tuple(
self.join_cols = tuple( (lhs_field.column, rhs_field.column)
(lhs_field.column, rhs_field.column) for lhs_field, rhs_field in self.join_fields
for lhs_field, rhs_field in self.join_fields )
)
else:
warnings.warn(
"The usage of get_joining_columns() in Join is deprecated. Implement "
"get_joining_fields() instead.",
RemovedInDjango60Warning,
)
self.join_fields = None
self.join_cols = join_field.get_joining_columns()
# Along which field (or ForeignObjectRel in the reverse join case) # Along which field (or ForeignObjectRel in the reverse join case)
self.join_field = join_field self.join_field = join_field
# Is this join nullabled? # Is this join nullabled?
@ -94,25 +82,15 @@ class Join:
join_conditions = [] join_conditions = []
params = [] params = []
qn = compiler.quote_name_unless_alias qn = compiler.quote_name_unless_alias
qn2 = connection.ops.quote_name
# Add a join condition for each pair of joining columns. # Add a join condition for each pair of joining columns.
# RemovedInDjango60Warning: when the depraction ends, replace with: for lhs, rhs in self.join_fields:
# for lhs, rhs in self.join_field: lhs, rhs = connection.ops.prepare_join_on_clause(
join_fields = self.join_fields or self.join_cols self.parent_alias, lhs, self.table_alias, rhs
for lhs, rhs in join_fields: )
if isinstance(lhs, str): lhs_sql, lhs_params = compiler.compile(lhs)
# RemovedInDjango60Warning: when the depraction ends, remove lhs_full_name = lhs_sql % lhs_params
# the branch for strings. rhs_sql, rhs_params = compiler.compile(rhs)
lhs_full_name = "%s.%s" % (qn(self.parent_alias), qn2(lhs)) rhs_full_name = rhs_sql % rhs_params
rhs_full_name = "%s.%s" % (qn(self.table_alias), qn2(rhs))
else:
lhs, rhs = connection.ops.prepare_join_on_clause(
self.parent_alias, lhs, self.table_alias, rhs
)
lhs_sql, lhs_params = compiler.compile(lhs)
lhs_full_name = lhs_sql % lhs_params
rhs_sql, rhs_params = compiler.compile(rhs)
rhs_full_name = rhs_sql % rhs_params
join_conditions.append(f"{lhs_full_name} = {rhs_full_name}") join_conditions.append(f"{lhs_full_name} = {rhs_full_name}")
# Add a single condition inside parentheses for whatever # Add a single condition inside parentheses for whatever

View File

@ -273,6 +273,14 @@ to remove usage of these features.
* The ``FORMS_URLFIELD_ASSUME_HTTPS`` transitional setting is removed. * The ``FORMS_URLFIELD_ASSUME_HTTPS`` transitional setting is removed.
* The ``django.db.models.sql.datastructures.Join`` no longer fallback to
``get_joining_columns()``.
* The ``get_joining_columns()`` method of ``ForeignObject`` and
``ForeignObjectRel`` is removed.
* The ``ForeignObject.get_reverse_joining_columns()`` method is be removed.
See :ref:`deprecated-features-5.1` for details on these changes, including how See :ref:`deprecated-features-5.1` for details on these changes, including how
to remove usage of these features. to remove usage of these features.

View File

@ -8,7 +8,6 @@ from django.db import models
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.utils import isolate_apps from django.test.utils import isolate_apps
from django.utils import translation from django.utils import translation
from django.utils.deprecation import RemovedInDjango60Warning
from .models import ( from .models import (
Article, Article,
@ -712,52 +711,3 @@ class TestCachedPathInfo(TestCase):
foreign_object_restored = pickle.loads(pickle.dumps(foreign_object)) foreign_object_restored = pickle.loads(pickle.dumps(foreign_object))
self.assertIn("path_infos", foreign_object_restored.__dict__) self.assertIn("path_infos", foreign_object_restored.__dict__)
self.assertIn("reverse_path_infos", foreign_object_restored.__dict__) self.assertIn("reverse_path_infos", foreign_object_restored.__dict__)
class GetJoiningDeprecationTests(TestCase):
def test_foreign_object_get_joining_columns_warning(self):
msg = (
"ForeignObject.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Membership.person.field.get_joining_columns()
self.assertEqual(ctx.filename, __file__)
def test_foreign_object_get_reverse_joining_columns_warning(self):
msg = (
"ForeignObject.get_reverse_joining_columns() is deprecated. Use "
"get_reverse_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Membership.person.field.get_reverse_joining_columns()
self.assertEqual(ctx.filename, __file__)
def test_foreign_object_rel_get_joining_columns_warning(self):
msg = (
"ForeignObjectRel.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Membership.person.field.remote_field.get_joining_columns()
self.assertEqual(ctx.filename, __file__)
def test_join_get_joining_columns_warning(self):
class CustomForeignKey(models.ForeignKey):
def __getattribute__(self, attr):
if attr == "get_joining_fields":
raise AttributeError
return super().__getattribute__(attr)
class CustomParent(models.Model):
value = models.CharField(max_length=255)
class CustomChild(models.Model):
links = CustomForeignKey(CustomParent, models.CASCADE)
msg = (
"The usage of get_joining_columns() in Join is deprecated. Implement "
"get_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
CustomChild.objects.filter(links__value="value")