Skip to content

[Fixes #14788] Replace creates a duplicate layer when the dataset has no ModelSchema - #14794

Merged
etj merged 3 commits into
masterfrom
ISSUE_14788
Dec 3, 2026
Merged

etj merged 3 commits into
masterfrom
ISSUE_14788

Conversation

@nrjadkry

@nrjadkry nrjadkry commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14788

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

For all pull requests:

  • Confirm you have read the contribution guidelines
  • You have sent a Contribution Licence Agreement (CLA) as necessary (not required for small changes, e.g., fixing typos in the documentation)
  • Make sure the first PR targets the master branch, eventual backports will be managed later. This can be ignored if the PR is fixing an issue that only happens in a specific branch, but not in newer ones.

The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):

  • There is a ticket in https://github.com/GeoNode/geonode/issues describing the issue/improvement/feature (a notable exemption is, changes not visible to end-users)
  • The issue connected to the PR must have Labels and Milestone assigned
  • PR for bug fixes and small new features are presented as a single commit
  • PR title must be in the form "[Fixes #<issue_number>] Title of the PR"
  • New unit tests have been added covering the changes, unless there is an explanation on why the tests are not necessary/implemented

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.

@cla-bot cla-bot Bot added the cla-signed CLA Bot: community license agreement signed label Nov 25, 2026
@giohappy
giohappy removed the request for review from mattiagiupponi December 2, 2026 10:20
@etj etj self-assigned this Dec 2, 2026

@etj etj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@nrjadkry
nrjadkry requested a review from etj December 3, 2026 08:26
@etj
etj merged commit dc179f2 into master Dec 3, 2026
15 checks passed
@etj
etj deleted the ISSUE_14788 branch December 3, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 5.1.x cla-signed CLA Bot: community license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace creates a duplicate layer when the dataset has no ModelSchema

2 participants