#36289 closed Bug (fixed)
Postgres bulk_create error when geometry is null or a different SRID
Description ¶
I have a model with a geometry field like this:
from django.contrib.gis.db import models class Garage(models.Model): name = models.CharField(max_length=100, blank=True) location = models.PointField(null=True, blank=True)
With Django 5.2 and PostgreSQL (17.4 / PostGIS 3.5.2), bulk_create
fails when I try to more than one item with a null location:
Garage.objects.bulk_create([Garage(), Garage()])
InternalError: parse error - invalid geometry LINE 1: ...stimes_garage" ("location") SELECT * FROM UNNEST(('{NULL,NUL... ^ HINT: "NU" <-- parse error at position 2 within geometry
or with an SRID other than the default
Garage.objects.bulk_create([Garage(location="SRID=29902;POINT(624210 307091)"), Garage(location="SRID=29902;POINT(624210 307091)")])
DataError: Geometry SRID (29902) does not match column SRID (4326)
This seems to be a regression in 5.2, maybe related to #35936 (Speeding up Postgres bulk_create by using unnest)
Change History (7)
comment:1 by , 3 days ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 3 days ago
The most simple solution is likely to adapt assemble_as_sql
to disable the optimization if any field has a geometry db type.
comment:3 by , 2 days ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:5 by , 28 hours ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Thank you for the report!
Replicated, regression in a16eedcf9c69d8a11d94cac1811018c5b996d491
Basic regression test if useful:
TabularUnified tests/gis_tests/geo3d/models.py
)TabularUnified tests/gis_tests/geo3d/tests.py