Opened 4 years ago

Last modified 15 months ago

#17018 new Bug

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

Reported by: grobertson 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 grobertson 4 years ago.
layermapping.2.patch (975 bytes) - added by grobertson 4 years ago.
updated patch
django-17018.diff (5.5 KB) - added by grobertson 4 years ago.
updated patch with tests
counties_null_state.dbf (258 bytes) - added by grobertson 4 years ago.
shapefile dbf for tests, put in django/contrib/gis/tests/data/counties
counties_null_state.shx (108 bytes) - added by grobertson 4 years ago.
shapefile shx for tests, put in django/contrib/gis/tests/data/counties
counties_null_state.shp (1.7 KB) - added by grobertson 4 years ago.
shapefile shp for tests, put in django/contrib/gis/tests/data/counties
django-17018.2.diff (5.5 KB) - added by grobertson 4 years ago.
Updated patch

Download all attachments as: .zip

Change History (12)

Changed 4 years ago by grobertson

comment:1 Changed 4 years ago by grobertson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from LayerMapping - entry skipped when ForeignKey field has related model missing and null = True to LayerMapping - entries skipped when ForeignKey field has related model missing and null = True

comment:2 Changed 4 years ago by aaugustin

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

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 4 years ago by grobertson

updated patch

Changed 4 years ago by grobertson

updated patch with tests

Changed 4 years ago by grobertson

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

Changed 4 years ago by grobertson

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

Changed 4 years ago by grobertson

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

comment:3 Changed 4 years ago by grobertson

  • Owner changed from nobody to aaugustin

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 4 years ago by aaugustin

  • Needs tests unset
  • Owner changed from aaugustin to nobody
  • Patch needs improvement unset

Changed 4 years ago by grobertson

Updated patch

comment:5 Changed 15 months ago by timo

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