Opened 13 years ago

Closed 13 years ago

#18367 closed Bug (fixed)

LayerMapping.verify_ogr_field fails when trying to map OFTString to TextField

Reported by: geoffhing@… Owned by: nobody
Component: GIS Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In LayerMapping.verify_ogr_field(), there is this check around line 335 of contrib/gis/utils/layermapping.py:

                val = ogr_field.value
                if len(val) > model_field.max_length:
                    raise InvalidString('%s model field maximum string length is %s, given %s characters.' %
                                        (model_field.name, model_field.max_length, len(val)))

When model_field is an instance of models.TextField this check will fail because model_field.max_length is None.

I was able to fix this by checking model_field.max_length before the length test:

                val = ogr_field.value
                if model_field.max_length and len(val) > model_field.max_length:
                    raise InvalidString('%s model field maximum string length is %s, given %s characters.' %
                                        (model_field.name, model_field.max_length, len(val)))

Change History (1)

comment:1 by Claude Paroz <claude@…>, 13 years ago

Resolution: fixed
Status: newclosed

In [f4abba5200e3164003781698c0854383bbc210be]:

Fixed #18367 -- Allowed LayerMapping to store strings in TextField.

Thanks geoffhing@… for the report.

Note: See TracTickets for help on using tickets.
Back to Top