Code

Opened 2 years ago

Closed 2 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:
Needs tests: Patch needs improvement:
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)))

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [f4abba5200e3164003781698c0854383bbc210be]:

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

Thanks geoffhing@… for the report.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.