Skip to content

Commit 2481613

Browse files
AlexCLeducAlexHill
authored andcommitted
add backwards compatibility
1 parent deb5be5 commit 2481613

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

relativity/fields.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def get_attname(self):
225225
def relationship_related_query_name(self):
226226
return self.remote_field.name
227227

228-
def get_extra_restriction(self, alias, related_alias):
228+
def _get_extra_restriction(self, alias, related_alias):
229229
return Restriction(
230230
forward=False,
231231
local_model=self.related_model,
@@ -235,6 +235,18 @@ def get_extra_restriction(self, alias, related_alias):
235235
predicate=self.field.predicate,
236236
)
237237

238+
def _get_extra_restriction_legacy(self, where_class, alias, related_alias):
239+
# this is a shim to maintain compatibility with django < 4.0
240+
return self._get_extra_restriction(alias, related_alias)
241+
242+
# this is required to handle a change in Django 4.0
243+
# https://docs.djangoproject.com/en/4.0/releases/4.0/#miscellaneous
244+
# the signature of the (private) funtion was changed
245+
if django.VERSION < (4, 0):
246+
get_extra_restriction = _get_extra_restriction_legacy
247+
else:
248+
get_extra_restriction = _get_extra_restriction
249+
238250
@classmethod
239251
def _resolve_expression_local_references(cls, expr, obj):
240252
if isinstance(expr, L):
@@ -351,7 +363,7 @@ def field(self):
351363
def get_accessor_name(self):
352364
return self.name
353365

354-
def get_extra_restriction(self, related_alias, local_alias):
366+
def _get_extra_restriction(self, related_alias, local_alias):
355367
return Restriction(
356368
forward=True,
357369
local_model=self.model,
@@ -361,6 +373,19 @@ def get_extra_restriction(self, related_alias, local_alias):
361373
predicate=self.predicate,
362374
)
363375

376+
def _get_extra_restriction_legacy(self, where_class, alias, related_alias):
377+
# this is a shim to maintain compatibility with django < 4.0
378+
return self._get_extra_restriction(alias, related_alias)
379+
380+
# this is required to handle a change in Django 4.0
381+
# https://docs.djangoproject.com/en/4.0/releases/4.0/#miscellaneous
382+
# the signature of the (private) funtion was changed
383+
if django.VERSION < (4, 0):
384+
get_extra_restriction = _get_extra_restriction_legacy
385+
else:
386+
get_extra_restriction = _get_extra_restriction
387+
388+
364389
def get_forward_related_filter(self, obj):
365390
"""
366391
Return the filter arguments which select the instances of self.model

0 commit comments

Comments
 (0)