Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mm committed Dec 23, 2023
2 parents cf4e41f + 14917c9 commit 6b1a4cb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
22 changes: 17 additions & 5 deletions django/contrib/gis/gdal/prototypes/geom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ctypes import POINTER, c_char_p, c_double, c_int, c_void_p

from django.contrib.gis.gdal.envelope import OGREnvelope
from django.contrib.gis.gdal.libgdal import lgdal
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
from django.contrib.gis.gdal.prototypes.errcheck import check_envelope
from django.contrib.gis.gdal.prototypes.generation import (
const_string_output,
Expand Down Expand Up @@ -52,9 +52,18 @@ def topology_func(f):
getz = pnt_func(lgdal.OGR_G_GetZ)

# Geometry creation routines.
from_wkb = geom_output(
lgdal.OGR_G_CreateFromWkb, [c_char_p, c_void_p, POINTER(c_void_p), c_int], offset=-2
)
if GDAL_VERSION >= (3, 3):
from_wkb = geom_output(
lgdal.OGR_G_CreateFromWkbEx,
[c_char_p, c_void_p, POINTER(c_void_p), c_int],
offset=-2,
)
else:
from_wkb = geom_output(
lgdal.OGR_G_CreateFromWkb,
[c_char_p, c_void_p, POINTER(c_void_p), c_int],
offset=-2,
)
from_wkt = geom_output(
lgdal.OGR_G_CreateFromWkt,
[POINTER(c_char_p), c_void_p, POINTER(c_void_p)],
Expand Down Expand Up @@ -88,7 +97,10 @@ def topology_func(f):
to_gml = string_output(
lgdal.OGR_G_ExportToGML, [c_void_p], str_result=True, decoding="ascii"
)
get_wkbsize = int_output(lgdal.OGR_G_WkbSize, [c_void_p])
if GDAL_VERSION >= (3, 3):
get_wkbsize = int_output(lgdal.OGR_G_WkbSizeEx, [c_void_p])
else:
get_wkbsize = int_output(lgdal.OGR_G_WkbSize, [c_void_p])

# Geometry spatial-reference related routines.
assign_srs = void_output(
Expand Down
6 changes: 4 additions & 2 deletions django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ def get_child_with_renamed_prefix(prefix, replacement, child):
return rename_prefix_from_q(prefix, replacement, child)
if isinstance(child, tuple):
lhs, rhs = child
lhs = lhs.replace(prefix, replacement, 1)
if lhs.startswith(prefix + LOOKUP_SEP):
lhs = lhs.replace(prefix, replacement, 1)
if not isinstance(rhs, F) and hasattr(rhs, "resolve_expression"):
rhs = get_child_with_renamed_prefix(prefix, replacement, rhs)
return lhs, rhs

if isinstance(child, F):
child = child.copy()
child.name = child.name.replace(prefix, replacement, 1)
if child.name.startswith(prefix + LOOKUP_SEP):
child.name = child.name.replace(prefix, replacement, 1)
elif hasattr(child, "resolve_expression"):
child = child.copy()
child.set_source_expressions(
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/5.0.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ Bugfixes
overflow the page and become non-interactive (:ticket:`35012`).

* Added compatibility for ``oracledb`` 2.0.0 (:ticket:`35054`).

* Fixed a regression in Django 5.0 where querysets referenced incorrect field
names from ``FilteredRelation()`` (:ticket:`35050`).
2 changes: 2 additions & 0 deletions tests/filtered_relation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Book(models.Model):
related_query_name="book",
)
editor = models.ForeignKey(Editor, models.CASCADE)
number_editor = models.IntegerField(default=-1)
editor_number = models.IntegerField(default=-2)
generic_author = GenericRelation(Author)
state = models.CharField(max_length=9, choices=STATES, default=AVAILABLE)

Expand Down
36 changes: 36 additions & 0 deletions tests/filtered_relation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,42 @@ def test_conditional_expression_with_multiple_fields(self):
).filter(my_books__isnull=True)
self.assertSequenceEqual(qs, [])

def test_conditional_expression_rhs_contains_relation_name(self):
qs = Book.objects.annotate(
rel=FilteredRelation(
"editor",
condition=Q(id=1 * F("number_editor")),
)
).filter(rel__isnull=True)
self.assertSequenceEqual(qs, [])

def test_conditional_expression_rhs_startswith_relation_name(self):
qs = Book.objects.annotate(
rel=FilteredRelation(
"editor",
condition=Q(id=1 * F("editor_number")),
)
).filter(rel__isnull=True)
self.assertSequenceEqual(qs, [])

def test_conditional_expression_lhs_startswith_relation_name(self):
qs = Book.objects.annotate(
rel=FilteredRelation(
"editor",
condition=Q(editor_number__gt=1),
)
).filter(rel__isnull=True)
self.assertSequenceEqual(qs, [])

def test_conditional_expression_lhs_contains_relation_name(self):
qs = Book.objects.annotate(
rel=FilteredRelation(
"editor",
condition=Q(number_editor__gt=1),
)
).filter(rel__isnull=True)
self.assertSequenceEqual(qs, [])


class FilteredRelationAggregationTests(TestCase):
@classmethod
Expand Down

0 comments on commit 6b1a4cb

Please sign in to comment.