Opened 5 years ago

Last modified 3 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 5 years ago.
layermapping.2.patch (975 bytes) - added by Glen Robertson 5 years ago.
updated patch
django-17018.diff (5.5 KB) - added by Glen Robertson 5 years ago.
updated patch with tests
counties_null_state.dbf (258 bytes) - added by Glen Robertson 5 years ago.
shapefile dbf for tests, put in django/contrib/gis/tests/data/counties
counties_null_state.shx (108 bytes) - added by Glen Robertson 5 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 5 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 5 years ago.
Updated patch

Download all attachments as: .zip

Change History (12)

Changed 5 years ago by Glen Robertson

Attachment: layermapping.patch added

comment:1 Changed 5 years ago by Glen Robertson

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 Changed 5 years ago by Aymeric Augustin

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.

Changed 5 years ago by Glen Robertson

Attachment: layermapping.2.patch added

updated patch

Changed 5 years ago by Glen Robertson

Attachment: django-17018.diff added

updated patch with tests

Changed 5 years ago by Glen Robertson

Attachment: counties_null_state.dbf added

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

Changed 5 years ago by Glen Robertson

Attachment: counties_null_state.shx added

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

Changed 5 years ago by Glen Robertson

Attachment: counties_null_state.shp added

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

comment:3 Changed 5 years ago by Glen Robertson

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 Changed 5 years ago by Aymeric Augustin

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

Changed 5 years ago by Glen Robertson

Attachment: django-17018.2.diff added

Updated patch

comment:5 Changed 3 years ago by Tim Graham

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