Skip to content

Commit e8329a6

Browse files
authored
Merge pull request #870 from DalgoT4D/bug/duplicate-model-name
Bug/duplicate model name
2 parents d98beb8 + 0709ae6 commit e8329a6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ddpui/api/transform_api.py

+16
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ def post_save_model(request, model_uuid: str, payload: CompleteDbtModelPayload):
364364
if not orgdbt_model:
365365
raise HttpError(404, "model not found")
366366

367+
# prevent duplicate models
368+
if (
369+
OrgDbtModel.objects.filter(orgdbt=orgdbt, name=payload.name)
370+
.exclude(uuid=orgdbt_model.uuid)
371+
.exists()
372+
):
373+
raise HttpError(422, "model with this name already exists")
374+
375+
# when you are overwriting the existing model with same name but different schema; which again leads to duplicate models
376+
if (
377+
payload.name == orgdbt_model.name
378+
and payload.dest_schema != orgdbt_model.schema
379+
and not orgdbt_model.under_construction
380+
):
381+
raise HttpError(422, "model with this name already exists in the schema")
382+
367383
check_canvas_locked(orguser, payload.canvas_lock_id)
368384

369385
payload.name = slugify(payload.name)

0 commit comments

Comments
 (0)