Repository navigation
Description
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
ModelSchemarow 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
Datasetrow 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
- 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 runupdatelayers. - Confirm the gap:
SELECT * FROM dynamic_models_modelschema WHERE name ILIKE '<dataset name>';returns no row, while the dataset exists inlayers_dataset. - In the UI, use Edit > Update dataset > Replace and upload a shapefile.
- 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
etj commentedon Nov 24, 2026
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 itsdefaultStyleat 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.
[Fixes #14788] Replace targets the existing table when the dataset ha…
[Fixes #14788] Reject replace of a missing dataset and add callback t…
[Fixes #14788] Replace creates a duplicate layer when the dataset has…
[Fixes #14788][5.1.x] Replace creates a duplicate layer when the data…