From 53fc6ac64976a7693d2272050a03b71e56b16578 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Sat, 6 Jan 2024 14:07:49 +0000 Subject: [PATCH] Fixed #35088 -- Added support for Collect on MySQL 8.0.24+. --- .../gis/db/backends/mysql/operations.py | 27 ++++++++++++++----- docs/ref/contrib/gis/db-api.txt | 18 ++++++------- docs/ref/contrib/gis/geoquerysets.txt | 6 ++++- docs/releases/5.1.txt | 3 +++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/django/contrib/gis/db/backends/mysql/operations.py b/django/contrib/gis/db/backends/mysql/operations.py index 886db605cd50..1004cfb56484 100644 --- a/django/contrib/gis/db/backends/mysql/operations.py +++ b/django/contrib/gis/db/backends/mysql/operations.py @@ -31,6 +31,11 @@ def select(self): def from_text(self): return self.geom_func_prefix + "GeomFromText" + @cached_property + def collect(self): + if self.connection.features.supports_collect_aggr: + return self.geom_func_prefix + "Collect" + @cached_property def gis_operators(self): operators = { @@ -54,13 +59,18 @@ def gis_operators(self): operators["relate"] = SpatialOperator(func="ST_Relate") return operators - disallowed_aggregates = ( - models.Collect, - models.Extent, - models.Extent3D, - models.MakeLine, - models.Union, - ) + @cached_property + def disallowed_aggregates(self): + disallowed_aggregates = [ + models.Extent, + models.Extent3D, + models.MakeLine, + models.Union, + ] + is_mariadb = self.connection.mysql_is_mariadb + if is_mariadb or self.connection.mysql_version < (8, 0, 24): + disallowed_aggregates.insert(0, models.Collect) + return tuple(disallowed_aggregates) function_names = { "FromWKB": "ST_GeomFromWKB", @@ -128,3 +138,6 @@ def converter(value, expression, connection): return geom return converter + + def spatial_aggregate_name(self, agg_name): + return getattr(self, agg_name.lower()) diff --git a/docs/ref/contrib/gis/db-api.txt b/docs/ref/contrib/gis/db-api.txt index f2dd1c7bf433..bce6f2efcca4 100644 --- a/docs/ref/contrib/gis/db-api.txt +++ b/docs/ref/contrib/gis/db-api.txt @@ -431,20 +431,20 @@ Aggregate Functions ------------------- The following table provides a summary of what GIS-specific aggregate functions -are available on each spatial backend. Please note that MySQL does not +are available on each spatial backend. Please note that MariaDB does not support any of these aggregates, and is thus excluded from the table. .. currentmodule:: django.contrib.gis.db.models -======================= ======= ====== ========== -Aggregate PostGIS Oracle SpatiaLite -======================= ======= ====== ========== -:class:`Collect` X X -:class:`Extent` X X X +======================= ======= ====== ============ ========== +Aggregate PostGIS Oracle MySQL SpatiaLite +======================= ======= ====== ============ ========== +:class:`Collect` X X (≥ 8.0.24) X +:class:`Extent` X X X :class:`Extent3D` X -:class:`MakeLine` X X -:class:`Union` X X X -======================= ======= ====== ========== +:class:`MakeLine` X X +:class:`Union` X X X +======================= ======= ====== ============ ========== .. rubric:: Footnotes .. [#fnwkt] *See* Open Geospatial Consortium, Inc., `OpenGIS Simple Feature Specification For SQL `_, Document 99-049 (May 5, 1999), at Ch. 3.2.5, p. 3-11 (SQL Textual Representation of Geometry). diff --git a/docs/ref/contrib/gis/geoquerysets.txt b/docs/ref/contrib/gis/geoquerysets.txt index 99b8638a65b3..c0dd8d71c822 100644 --- a/docs/ref/contrib/gis/geoquerysets.txt +++ b/docs/ref/contrib/gis/geoquerysets.txt @@ -870,7 +870,7 @@ Example: .. class:: Collect(geo_field, filter=None) -*Availability*: `PostGIS `__, +*Availability*: `PostGIS `__, MySQL, SpatiaLite Returns a ``GEOMETRYCOLLECTION`` or a ``MULTI`` geometry object from the geometry @@ -883,6 +883,10 @@ caring about dissolving boundaries. Support for using the ``filter`` argument was added. +.. versionchanged:: 5.1 + + MySQL 8.0.24+ support was added. + ``Extent`` ~~~~~~~~~~ diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt index 03ca07f298d2..e84a27a0ec42 100644 --- a/docs/releases/5.1.txt +++ b/docs/releases/5.1.txt @@ -56,6 +56,9 @@ Minor features * :class:`~django.contrib.gis.db.models.functions.BoundingCircle` is now supported on SpatiaLite 5.1+. +* :class:`~django.contrib.gis.db.models.Collect` is now supported on MySQL + 8.0.24+. + :mod:`django.contrib.messages` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~