[Django] #37135: LayerMapping utility seems unable to import PointFields with "unique" keyword parameter

2 views
Skip to first unread message

Django

unread,
Jun 1, 2026, 8:45:48 AM (yesterday) Jun 1
to django-...@googlegroups.com
#37135: LayerMapping utility seems unable to import PointFields with "unique"
keyword parameter
-------------------------------+--------------------------------------
Reporter: Agnès Haasser | Type: Bug
Status: new | Component: GIS
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Hello,

I'm trying to use LayerMapping in order to import Geographic Data in my
database, in "update" mode. That is, I use "unique" parameter to check if
LayerMapping should update existing entries or create new ones:


{{{
lm = LayerMapping(
target_class,
path_to_my_shp_file,
my_mapping,
unique=tuple_of_django_fields,
)
lm.save(strict=True, verbose=True)
}}}


When target_class has a geometry of type PointField, I get an error:



{{{
'Point' object is not iterable
Traceback (most recent call last):
File "file_on_disk/sia/gis_import/views.py", line 12, in launch_import
databatch.import_geographic_data()
File "file_on_disk/sia/gis_import/models.py", line 66, in
import_geographic_data
lm.save(strict=True, verbose=True)
File "file_on_disk/venv/lib/python3.11/site-
packages/django/contrib/gis/utils/layermapping.py", line 728, in save
_save()
File "file_on_disk/venv/lib/python3.11/site-
packages/django/contrib/gis/utils/layermapping.py", line 653, in _save
for g in new:
TypeError: 'Point' object is not iterable
}}}

I'm using Django 5.2 so I have an older version of layermapping but it
seems the bug is still here in present source code (6.2 is not out yet as
I write this ticket):

https://github.com/django/django/blob/ea9742c6d02edf64fc0969f21506f2048c976051/django/contrib/gis/utils/layermapping.py#L661-L663
--
Ticket URL: <https://code.djangoproject.com/ticket/37135>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages