              placeholder, _ = compiler.compile(value)
          else:
              placeholder = '%s(%%s)' % self.from_text
          return placeholder
 
</s> remove             if spatialite or mysql or oracle:
 </s> add             if spatialite or (mysql and not connection.ops.uses_invalid_empty_geometry_collection) or oracle: </s> remove from django.contrib.gis.db.models import aggregates
 </s> add from django.contrib.gis.db.models import GeometryField, aggregates
    def get_db_converters(self, expression):
        converters = super(MySQLOperations, self).get_db_converters(expression)
        if isinstance(expression.output_field, GeometryField) and self.uses_invalid_empty_geometry_collection:
            converters.append(self.convert_invalid_empty_geometry_collection)
        return converters

    # https://dev.mysql.com/doc/refman/5.7/en/spatial-function-argument-handling.html
    # MySQL 5.7.5 adds support for the empty geometry collections, but they are represented with invalid WKT.
    def convert_invalid_empty_geometry_collection(self, value, expression, connection, context):
        if value == b'GEOMETRYCOLLECTION()':
            return b'GEOMETRYCOLLECTION EMPTY'
        return value
              placeholder, _ = compiler.compile(value)
          else:
              placeholder = '%s(%%s)' % self.from_text
          return placeholder
    def get_db_converters(self, expression):
        converters = super(MySQLOperations, self).get_db_converters(expression)
        if isinstance(expression.output_field, GeometryField) and self.uses_invalid_empty_geometry_collection:
            converters.append(self.convert_invalid_empty_geometry_collection)
        return converters

    # https://dev.mysql.com/doc/refman/5.7/en/spatial-function-argument-handling.html
    # MySQL 5.7.5 adds support for the empty geometry collections, but they are represented with invalid WKT.
    def convert_invalid_empty_geometry_collection(self, value, expression, connection, context):
        if value == b'GEOMETRYCOLLECTION()':
            return b'GEOMETRYCOLLECTION EMPTY'
        return value
keep keep keep add
 Refs #26657 -- Fixed a crash induced by invalid WKT returned by MySQL 5.7.5+. 
django/contrib/gis/db/backends/mysql/operations.py