Skip to content

Replace creates a duplicate layer when the dataset has no ModelSchema #14788

Description

@etj

Summary

A "replace dataset" on a vector dataset that has no corresponding ModelSchema row silently publishes a new layer under a generated alternate instead of replacing the existing one. The original dataset is left untouched with its old data, and the uploaded data ends up in a layer that exists only in GeoServer. No error is raised and the upload reports success.

This affects datasets that predate the dynamic-model importer, or that entered the catalogue by any route that did not create a ModelSchema — restored backups, updatelayers, direct GeoServer publication followed by a sync.

Affected versions

Present since the importer was merged into core — b6a26f3, "[Fixes #12368] Introduce geonode-importer in geonode-core (#12570)", 2024-10-16. Not a recent regression.

Tags: 5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.1.0, 5.1.1. Branches: master, 5.1.x, 5.0.x.

Vector uploads only. The raster handler resolves the same question correctly and does not consult ModelSchema, since rasters do not use dynamic models.

Where

geonode/upload/handlers/common/vector.py, setup_dynamic_model(). Line numbers from 5.1.x at 70e368de1.

The in-place replace requires all three conditions (line 719):

if dataset_exists and dynamic_schema_exists and should_be_overwritten:
    dynamic_schema = dynamic_schema.get()
    layer_name = available_dataset.first().alternate.split(":")[-1]

Anything else falls through to (line 747):

elif (
    (not dataset_exists and dynamic_schema_exists)
    or (dataset_exists and dynamic_schema_exists and not should_be_overwritten)
    or (dataset_exists and not dynamic_schema_exists)
):
    """
    The layer should not be overwritten so we append the UUID
    to the layer name to let it proceed to the next steps
    """
    layer_name = create_alternate(layer_name, execution_id)

The third condition, dataset_exists and not dynamic_schema_exists, does not test should_be_overwritten. When the user has explicitly requested a replace and the dataset exists, the only thing missing is the ModelSchema — yet the code takes the "do not overwrite" branch. The docstring states the user's intent incorrectly for this case.

find_alternate_by_dataset() at line 642 disagrees with this for the same upload. Given a resource_pk it returns the existing alternate unconditionally:

if _exec_obj.input_params.get("resource_pk"):
    dataset = Dataset.objects.filter(pk=_exec_obj.input_params.get("resource_pk")).first()
    ...
    alternate = dataset.alternate.split(":")
    return alternate[-1]

So one function resolves the name to the existing alternate and the other generates a fresh one.

Observed result

Replacing a shapefile on a dataset with no ModelSchema produced, in a single execution:

  • the uploaded data in a new PostGIS table named after the generated alternate, with a new ModelSchema row pointing at it
  • a new GeoServer feature type and layer for that table, with no catalogue metadata and the generic workspace style
  • the original GeoNode dataset unchanged, still pointing at the original table with the original columns
  • the GWC tile layer moved to the new layer, leaving the original without one
  • exactly one Dataset row in GeoNode, so the duplicate is reachable only through GeoServer

The two tables had entirely disjoint schemas, so the replace amounted to publishing a second, unrelated layer while reporting success.

Reproduction

  1. Publish a vector dataset by a route that does not create a ModelSchema — for example restore a GeoNode backup, or publish directly in GeoServer and run updatelayers.
  2. Confirm the gap: SELECT * FROM dynamic_models_modelschema WHERE name ILIKE '<dataset name>'; returns no row, while the dataset exists in layers_dataset.
  3. In the UI, use Edit > Update dataset > Replace and upload a shapefile.
  4. The upload succeeds. GeoServer now holds <name> and <name>_<md5>, and the new data is in the second one.

Suggested fix

When should_be_overwritten is true and the dataset exists, the user's intent is unambiguous and the missing ModelSchema is the thing to repair, not a reason to branch. Either create the schema against the existing table and continue down the overwrite path, or fail loudly so the condition is visible — publishing a divergent second layer and reporting success is the worst of the three.

The two functions should also agree on how the target alternate is resolved, so that resource_pk means the same thing in both.

find_alternate_by_dataset() and BaseRasterFileHandler both treat should_be_overwritten as decisive when the dataset exists; setup_dynamic_model() is the only one of the three that does not.

Activity

  1. added this to the 5.2.0 milestone on Nov 24, 2026
  2. etj commented on Nov 24, 2026

    @etj
    ContributorAuthor

    Small correction to "the original dataset is left untouched": its data is, but the existing GeoServer layer is modified in the same execution. In the case observed, within a 15-second window the run created the duplicate layer, then rewrote the original layer's featuretype.xml (adding metadata links) and repointed its defaultStyle at a newly created style.

    So the replace half-applies — it updates the existing layer's styling and metadata while publishing the data elsewhere. I have not traced which step does this, so treat it as an observation rather than part of the diagnosis above.

  3. modified the milestones: 5.2.0, 5.1.2 on Dec 2, 2026
  4. added 2 commits that reference this issue on Dec 3, 2026
    45d16fd
    9274f38
  5. added a commit that references this issue on Dec 3, 2026
    dc179f2
  6. added a commit that references this issue on Dec 3, 2026
    6f53374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions