Skip to content

Commit

Permalink
Merge pull request #870 from DalgoT4D/bug/duplicate-model-name
Browse files Browse the repository at this point in the history
Bug/duplicate model name
  • Loading branch information
Ishankoradia authored Sep 30, 2024
2 parents d98beb8 + 0709ae6 commit e8329a6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ddpui/api/transform_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ def post_save_model(request, model_uuid: str, payload: CompleteDbtModelPayload):
if not orgdbt_model:
raise HttpError(404, "model not found")

# prevent duplicate models
if (
OrgDbtModel.objects.filter(orgdbt=orgdbt, name=payload.name)
.exclude(uuid=orgdbt_model.uuid)
.exists()
):
raise HttpError(422, "model with this name already exists")

# when you are overwriting the existing model with same name but different schema; which again leads to duplicate models
if (
payload.name == orgdbt_model.name
and payload.dest_schema != orgdbt_model.schema
and not orgdbt_model.under_construction
):
raise HttpError(422, "model with this name already exists in the schema")

check_canvas_locked(orguser, payload.canvas_lock_id)

payload.name = slugify(payload.name)
Expand Down

0 comments on commit e8329a6

Please sign in to comment.