Skip to content

Avoid duplicate key error messages when inserting state record

What does this MR do and why?

This MR stops emitting duplicate key error message on Terraform state record creation:

duplicate key value violates unique constraint "index_terraform_states_on_project_id_and_name"

This confuses SREs time to time such as:

We switch to safe_find_or_create_by as a short term fix, as the approach executes SELECT first to find an existing row, and this approach doesn't cause subtransaction issue at the moment. We'll follow-up in the future to seek a way for completely subtransaction free approach. Related to https://gitlab.slack.com/archives/C04SS157XSQ/p1679074934033949.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Shinya Maeda

Merge request reports