Will only create 632 WMCF areas although there are 650 areas in the dataset. Turns out the culprit is this bit of code in mapit/add_areas_from_file/core.py:
if parameters.new: # Always want a new area
raise Area.DoesNotExist
if code:
matching_message = "code %s of code type %s" % (
code,
parameters.code_type,
)
areas = Area.objects.filter(
codes__code=code, codes__type=parameters.code_type
).order_by("-generation_high")
else:
matching_message = "name %s of area type %s" % (
name,
parameters.area_type,
)
areas = Area.objects.filter(
name=name, type=parameters.area_type
).order_by("-generation_high")
Workaround
On the initial import use --preserve to force creating new areas.
No workaround for updating areas.
Proposed change
If both codes and an area type is specified when importing the script should filter by both. In particular it should never touch areas of another type than the one specified as --area_type_code.
Problem
When importing using
mapit_import
you can’t import codes while also filtering for an area type:--code_field
/--code_type
and--area_type_code
then the area type is ignored when searching for existing areas.--area_type_code
then the codes are not imported.When one code is used in multiple area types this can lead to areas of a different type being modified.
Steps to reproduce
I observed this when importing the WMCF areas because there are a few scottish constituencies which keep their area code. Importing them with:
Will only create 632 WMCF areas although there are 650 areas in the dataset. Turns out the culprit is this bit of code in
mapit/add_areas_from_file/core.py
:Workaround
--preserve
to force creating new areas.Proposed change
If both codes and an area type is specified when importing the script should filter by both. In particular it should never touch areas of another type than the one specified as
--area_type_code
.