#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.