[Django] #37242: LayerMapping doesn't handle missing times, just missing date and datetime

10 views
Skip to first unread message

Django

unread,
Jul 31, 2026, 4:47:33 PM (2 days ago) Jul 31
to django-...@googlegroups.com
#37242: LayerMapping doesn't handle missing times, just missing date and datetime
-------------------------------------+-------------------------------------
Reporter: Jacob | Owner: Jacob Walls
Walls |
Type: Bug | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Keywords: DataSource,
Triage Stage: | LayerMapping
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
When parsing GDAL `LayerMapping` objects, `Field.as_datetime()` returns
None for an unset field. Both `OFTDate.value` and `OFTDateTime.value`
catch the resulting unpacking `TypeError`, but `OFTTime.value` does not:

For example, adjust this recently merged test data edit for #36626 (this
might actually be sufficient for a regression test, since this is all I
wanted to do at the time of merging):
{{{#!diff
diff --git a/tests/gis_tests/gdal_tests/test_ds.py
b/tests/gis_tests/gdal_tests/test_ds.py
index ea16c06f4a..a5904cbbc7 100644
--- a/tests/gis_tests/gdal_tests/test_ds.py
+++ b/tests/gis_tests/gdal_tests/test_ds.py
@@ -110,7 +110,7 @@ ds_list = (
None,
datetime.strptime("2018-11-29T03:02:52",
datetime_format),
],
- "time": [time(11, 32, 14, 123000), time(0), time(3, 2, 52)],
+ "time": [time(11, 32, 14, 123000), None, time(3, 2, 52)],
},
fids=range(3),
),
}}}
{{{#!py
File "/django/source/tests/gis_tests/gdal_tests/test_ds.py", line 199,
in test03a_layers
self.assertEqual(fld_value, layer.get_fields(fld_name))

File "/django/source/django/contrib/gis/gdal/layer.py", line 212, in
get_fields
return [feat.get(field_name) for feat in self]
^^^^^^^^^^^^^^^
File "/django/source/django/contrib/gis/gdal/feature.py", line 113, in
get
return self[field_name].value
^^^^^^^^^^^^^^^
File "/django/source/django/contrib/gis/gdal/field.py", line 216, in
value
yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
^^^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType object
}}}


Seems like a minor oversight in 75d627888bf42f8de6064a0bd665c98c0df66c55
(#30020).
--
Ticket URL: <https://code.djangoproject.com/ticket/37242>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 31, 2026, 4:53:18 PM (2 days ago) Jul 31
to django-...@googlegroups.com
#37242: LayerMapping doesn't handle missing times, just missing date and datetime
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: DataSource, | Triage Stage:
LayerMapping | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1


Old description:
New description:

When parsing GDAL `LayerMapping` objects, `Field.as_datetime()` returns
None for an unset field. Both `OFTDate.value` and `OFTDateTime.value`
catch the resulting unpacking `TypeError`, but `OFTTime.value` does not:

For example, adjust this recently merged test data edit for #36626 (this
might actually be sufficient for a regression test, since this is all I
wanted to do at the time of merging):
{{{#!diff
diff --git a/tests/gis_tests/data/has_nulls/has_nulls.geojson
b/tests/gis_tests/data/has_nulls/has_nulls.geojson
index 8ae52a1877..3bd34308fe 100644
--- a/tests/gis_tests/data/has_nulls/has_nulls.geojson
+++ b/tests/gis_tests/data/has_nulls/has_nulls.geojson
@@ -59,7 +59,6 @@
"type": "Feature",
"properties": {
"uuid": "fa2ba67c-a135-4338-b924-a9622b5d869f",
- "time": "00:00:00",
"integer": null,
"num": null
},
Comment:

[https://github.com/django/django/pull/21712 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/37242#comment:1>

Django

unread,
Aug 1, 2026, 2:16:33 PM (2 days ago) Aug 1
to django-...@googlegroups.com
#37242: LayerMapping doesn't handle missing times, just missing date and datetime
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: DataSource, | Triage Stage: Accepted
LayerMapping |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Smith):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/37242#comment:2>

Django

unread,
Aug 2, 2026, 9:02:56 AM (17 hours ago) Aug 2
to django-...@googlegroups.com
#37242: LayerMapping doesn't handle missing times, just missing date and datetime
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: DataSource, | Triage Stage: Ready for
LayerMapping | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Smith):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/37242#comment:3>

Django

unread,
Aug 2, 2026, 5:50:53 PM (8 hours ago) Aug 2
to django-...@googlegroups.com
#37242: LayerMapping doesn't handle missing times, just missing date and datetime
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: GIS | Version: dev
Severity: Normal | Resolution: fixed
Keywords: DataSource, | Triage Stage: Ready for
LayerMapping | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"2cace96be6d64b7dde7eb66d3ffc2c7f08ef644f" 2cace96]:
{{{#!CommitTicketReference repository=""
revision="2cace96be6d64b7dde7eb66d3ffc2c7f08ef644f"
Fixed #37242 -- Fixed reading null time fields in LayerMapping.

Follow-up to 75d627888bf42f8de6064a0bd665c98c0df66c55.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37242#comment:4>
Reply all
Reply to author
Forward
0 new messages