Skip to content

Commit d3703f6

Browse files
authored
Merge pull request #177 from GeoNode/fix_dynamicmodel
Fix issue with the resource rollback with the dynamic model disabled
2 parents 1bcb9fa + 1131024 commit d3703f6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

importer/handlers/common/vector.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,13 @@ def create_ogr2ogr_command(files, original_name, ovverwrite_layer, alternate):
168168
@staticmethod
169169
def delete_resource(instance):
170170
"""
171-
Base function to delete the resource with all the dependencies (example: dynamic model)
171+
Base function to delete the resource with all the dependencies (dynamic model)
172172
"""
173173
try:
174174
name = instance.alternate.split(":")[1]
175-
schema = ModelSchema.objects.filter(name=name).first()
175+
schema = None
176+
if os.getenv("IMPORTER_ENABLE_DYN_MODELS", False):
177+
schema = ModelSchema.objects.filter(name=name).first()
176178
if schema:
177179
'''
178180
We use the schema editor directly, because the model itself is not managed
@@ -181,7 +183,6 @@ def delete_resource(instance):
181183
_model_editor = ModelSchemaEditor(initial_model=name, db_name=schema.db_name)
182184
_model_editor.drop_table(schema.as_model())
183185
ModelSchema.objects.filter(name=name).delete()
184-
# Removing Field Schema
185186
except Exception as e:
186187
logger.error(f"Error during deletion of Dynamic Model schema: {e.args[0]}")
187188

@@ -690,7 +691,9 @@ def _import_resource_rollback(self, exec_id, instance_name=None, *args, **kwargs
690691
on creation, but for the delete since we are going to handle, we can use it
691692
'''
692693
logger.info(f"Rollback dynamic model & ogr2ogr step in progress for execid: {exec_id} resource published was: {instance_name}")
693-
schema = ModelSchema.objects.filter(name=instance_name).first()
694+
schema = None
695+
if os.getenv("IMPORTER_ENABLE_DYN_MODELS", False):
696+
schema = ModelSchema.objects.filter(name=instance_name).first()
694697
if schema is not None:
695698
_model_editor = ModelSchemaEditor(initial_model=instance_name, db_name=schema.db_name)
696699
_model_editor.drop_table(schema.as_model())

0 commit comments

Comments
 (0)