Repository navigation
[Fixes #14788] Replace creates a duplicate layer when the dataset has no ModelSchema - #14794
Conversation
… no ModelSchema
etj
left a comment
There was a problem hiding this comment.
Lookup key and write key disagree. Line 670 still reads ModelSchema.objects.filter(name__iexact=user_dataset.name) while the new get_or_create writes name=<alternate>. The rest of the file keys on the alternate (___get_dynamic_schema(), and -nln {alternate} in create_ogr2ogr_command). Where name != alternate — routine after an earlier duplicate import — the lookup can match a different dataset's schema and dynamic_schema.get() returns it. #14788 asked that the two resolutions agree:
dynamic_schema = ModelSchema.objects.filter(name__iexact=user_dataset.alternate.split(":")[-1])The rollback now drops live tables. import_resource()'s except calls drop_dynamic_model_schema(dynamic_model), which issues drop_table() unconditionally (independent of managed, failures only logged). Previously a failed replace of a no-ModelSchema dataset dropped the throwaway duplicate; now it drops the original table. The hazard already exists for datasets that have a schema, but this extends it to the ones least likely to have a second copy. Skip the drop when should_be_overwritten is true?
Dead code. The elif is now equivalent to else:, and the trailing else: raise ImportException(...) is unreachable.
managed: is_dynamic_model_managed in the new defaults. Unreachable today, but if it ever became true here, FieldSchemaEditor.add_column() has no guard against existing columns. Force False on this branch.
Tests. _assert_test_result only asserts assertIsNotNone, so test_setup_dynamic_model_*_overwrite_True changed behaviour under this PR without failing. A case where dataset.name != dataset.alternate would cover the first point.
…s no ModelSchema and never drops it on failure
Fixes #14788
Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.