Opened 12 years ago
Closed 12 years ago
#18367 closed Bug (fixed)
LayerMapping.verify_ogr_field fails when trying to map OFTString to TextField
Reported by: | 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)))
Note:
See TracTickets
for help on using tickets.
In [f4abba5200e3164003781698c0854383bbc210be]: