#Issue with postgis + Django 5.2 on `bulk_create`

4 messages · Page 1 of 1 (latest)

mighty veldt
#

Hey folks, nice to meet you all.

It's my fist time posting here, so let me know if I should move this elsewhere.

I'm in the process of upgrading one of my current projects to Django 5.2, and stumbled across a very strange issue when trying to bulk_create objects that have a nullable, geography Polygon field (GeoDjango).

If it create the save the instances manually using place_instance.save(), everything works as expected.
However, if I have a list of those instances and Place.objects.bulk_create(place_instance_list) I get the following error:

django.db.utils.InternalError: parse error - invalid geometry
LINE 1: ...ULL,NULL,NULL,NULL])::geography(POLYGON,4326)[], ('{NULL,NUL...
                                                             ^
HINT:  "NU" <-- parse error at position 2 within geometry

Additional context:

  • The model field is set up like this: shape = models.PolygonField(null=True, blank=True, geography=True).
  • This operation is running inside a transaction when failing.
  • Postgres 15, Postgis 3.5, Django 5.2, Python 3.10
  • Works just fine on Django 5.1 and the same setup.

These are the lines I've used to test the issue (out of context, for now):

# This works
for i in items_to_create:
    i.save()

# This doesn't
Place.objects.bulk_create(
    items_to_create, ignore_conflicts=True
)

Is there anything obvious that I'm missing here?
I'll see if I can get a reproducible example set up somewhere.

Thanks for the help in advance! 😁

mighty veldt
#

I noticed that the SQL statement is being compiled to:

    # non-related varchar field
    (ARRAY ['11','12']) :: varchar(50) [],
    # geometry field, ended up as a string.
    ('{NULL,NULL}') :: geometry(MULTILINESTRING, 4326) [],
mighty veldt
mighty veldt