Opened 70 minutes ago

Last modified 64 minutes ago

#37242 assigned Bug

LayerMapping doesn't handle missing times, just missing date and datetime

Reported by: Jacob Walls Owned by: Jacob Walls
Component: GIS Version: dev
Severity: Normal Keywords: DataSource, LayerMapping
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Jacob Walls)

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):

  • tests/gis_tests/data/has_nulls/has_nulls.geojson

    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 b  
    5959      "type": "Feature",
    6060      "properties": {
    6161        "uuid": "fa2ba67c-a135-4338-b924-a9622b5d869f",
    62         "time": "00:00:00",
    6362        "integer": null,
    6463        "num": null
    6564      },
  • tests/gis_tests/gdal_tests/test_ds.py

    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 b ds_list = (  
    110110                None,
    111111                datetime.strptime("2018-11-29T03:02:52", datetime_format),
    112112            ],
    113             "time": [time(11, 32, 14, 123000), time(0), time(3, 2, 52)],
     113            "time": [time(11, 32, 14, 123000), None, time(3, 2, 52)],
    114114        },
    115115        fids=range(3),
    116116    ),
  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).

Change History (1)

comment:1 by Jacob Walls, 64 minutes ago

Description: modified (diff)
Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top