Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/duplicate model name #870

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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")

Check warning on line 373 in ddpui/api/transform_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/transform_api.py#L373

Added line #L373 was not covered by tests

# 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 warning on line 381 in ddpui/api/transform_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/transform_api.py#L381

Added line #L381 was not covered by tests

check_canvas_locked(orguser, payload.canvas_lock_id)

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