Skip to content

Commit c4b01d8

Browse files
[Backport 5.0.x] [Fixes #14061] Upsert does not work after performing a replace on the… (#14063)
1 parent df237c4 commit c4b01d8

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

geonode/upload/celery_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def create_geonode_resource(
535535
handler.create_resourcehandlerinfo(handler_module_path, resource, _exec, **kwargs)
536536

537537
if _overwrite and handler.have_table:
538-
handler.fixup_dynamic_model_fields(_exec, _files)
538+
handler.fixup_dynamic_model_fields(_exec, _files, resource=resource)
539539

540540
# at the end recall the import_orchestrator for the next step
541541
import_orchestrator.apply_async(

geonode/upload/handlers/common/raster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def _publish_resource_rollback(self, exec_id, instance_name=None, *args, **kwarg
569569
publisher = DataPublisher(handler_module_path=handler_module_path)
570570
publisher.delete_resource(instance_name)
571571

572-
def fixup_dynamic_model_fields(self, _exec, files):
572+
def fixup_dynamic_model_fields(self, _exec, files, **kwargs):
573573
"""
574574
Raster dataset does not have the dynamic model, so this can be skept
575575
"""

geonode/upload/handlers/common/vector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,14 +1473,17 @@ def refresh_geonode_resource(self, execution_id, asset=None, dataset=None, creat
14731473
self.__fixup_primary_key(dataset)
14741474
return dataset
14751475

1476-
def fixup_dynamic_model_fields(self, _exec, files):
1476+
def fixup_dynamic_model_fields(self, _exec, files, **kwargs):
14771477
"""
14781478
Utility needed during the replace workflow,
14791479
it will sync all the FieldSchema along with the current resource uploaded.
14801480
This is mandatory in order to have a reliable field structure in the DB
14811481
"""
14821482
fields_schema, needed_field_schema = self.__get_new_and_original_schema(files, str(_exec.exec_id))
14831483
fields_schema.filter(~Q(name__in=(x["name"] for x in needed_field_schema))).delete()
1484+
if dataset := kwargs.get("resource", None):
1485+
self.__fixup_primary_key(dataset)
1486+
14841487

14851488

14861489
@importer_app.task(

0 commit comments

Comments
 (0)