﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37250	GeometryCollection should be an allowed type for GeometryCollection	Jacob Walls	Jacob Walls	"The multivalued geometry fields, e.g. `Multipolygon` define which classes they can contain, e.g. `Polygon` and not `Point` via the private attribute `_allowed`.

`GeometryCollection` is generic, so it contains all the others:

{{{#!py
# Setting the allowed types here since GeometryCollection is defined before
# its subclasses.
GeometryCollection._allowed = (
    Point,
    LineString,
    LinearRing,
    Polygon,
    MultiPoint,
    MultiLineString,
    MultiPolygon,
)
}}}

However, this list should also contain itself, since `GeometryCollection` can be nested.

In other words, this should work:
{{{#!diff
diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py
index 8659b660b6..16b5c74951 100644
--- a/django/contrib/gis/geos/collections.py
+++ b/django/contrib/gis/geos/collections.py
@@ -123,4 +123,5 @@ GeometryCollection._allowed = (
     MultiPoint,
     MultiLineString,
     MultiPolygon,
+    GeometryCollection,
 )
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 025e4fb4f3..e1a531b979 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -1347,6 +1347,10 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
         # And, they should be equal.
         self.assertEqual(gc1, gc2)
 
+        # Should also construct ok from GeometryCollection.
+        gc3 = GeometryCollection(gc2)
+        self.assertEqual(gc1, gc3[0])
+
     def test_gdal(self):
         ""Testing `ogr` and `srs` properties.""
         g1 = fromstr(""POINT(5 23)"")
}}}"	Bug	assigned	GIS	6.0	Normal				Unreviewed	0	0	0	0	0	0
