Opened 12 years ago

Last modified 10 years ago

#17018 new Bug

LayerMapping - entries skipped when ForeignKey field has related model missing and null = True

Reported by: Glen Robertson Owned by: nobody
Component: GIS Version: 1.3
Severity: Normal Keywords: geodjango, layermapping
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

The LayerMapping utility will skip entries for a model that has missing foreign key entries when the foreign key field has null=True in it's configuration.
It would be better to add these entries and set the model's foreign key value to None when the foreign key doesn't exist.

Attachments (7)

layermapping.patch (909 bytes ) - added by Glen Robertson 12 years ago.
layermapping.2.patch (975 bytes ) - added by Glen Robertson 12 years ago.
updated patch
django-17018.diff (5.5 KB ) - added by Glen Robertson 12 years ago.
updated patch with tests
counties_null_state.dbf (258 bytes ) - added by Glen Robertson 12 years ago.
shapefile dbf for tests, put in django/contrib/gis/tests/data/counties
counties_null_state.shx (108 bytes ) - added by Glen Robertson 12 years ago.
shapefile shx for tests, put in django/contrib/gis/tests/data/counties
counties_null_state.shp (1.7 KB ) - added by Glen Robertson 12 years ago.
shapefile shp for tests, put in django/contrib/gis/tests/data/counties
django-17018.2.diff (5.5 KB ) - added by Glen Robertson 12 years ago.
Updated patch

Download all attachments as: .zip

Change History (12)

by Glen Robertson, 12 years ago

Attachment: layermapping.patch added

comment:1 by Glen Robertson, 12 years ago

Summary: LayerMapping - entry skipped when ForeignKey field has related model missing and null = TrueLayerMapping - entries skipped when ForeignKey field has related model missing and null = True

comment:2 by Aymeric Augustin, 12 years ago

Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Two minor remarks:

  • please generate the patch from the "trunk" directory;
  • within an except clause, you can simply use raise to raise the current exception.

by Glen Robertson, 12 years ago

Attachment: layermapping.2.patch added

updated patch

by Glen Robertson, 12 years ago

Attachment: django-17018.diff added

updated patch with tests

by Glen Robertson, 12 years ago

Attachment: counties_null_state.dbf added

shapefile dbf for tests, put in django/contrib/gis/tests/data/counties

by Glen Robertson, 12 years ago

Attachment: counties_null_state.shx added

shapefile shx for tests, put in django/contrib/gis/tests/data/counties

by Glen Robertson, 12 years ago

Attachment: counties_null_state.shp added

shapefile shp for tests, put in django/contrib/gis/tests/data/counties

comment:3 by Glen Robertson, 12 years ago

Owner: changed from nobody to Aymeric Augustin

As above I have added attachments for an updated patch that includes unit tests.
They require the 3 files counties_null_state.* in the django/contrib/gis/tests/data/counties directory

I also modified the original patch to do the checking in the verify_fk method.

Cheers,
Glen

comment:4 by Aymeric Augustin, 12 years ago

Needs tests: unset
Owner: changed from Aymeric Augustin to nobody
Patch needs improvement: unset

by Glen Robertson, 12 years ago

Attachment: django-17018.2.diff added

Updated patch

comment:5 by Tim Graham, 10 years ago

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top