Skip to content

Upsert container repositories when finding or creating them

What does this MR do and why?

In this MR, we use upsert to create container repositories instead of safe_find_or_create_by to avoid a race condition where there are multiple attempts to create the same exact container repository, making the uniqueness check fail.

Previously, we had the timeout solution, but with feedback from our database maintainers, we were recommended to use upsert instead.

In #428115 (closed), we see that for some setups, safe_find_or_create_by returns a repository that is not yet persisted. That method uses transactions and it's possible that the transaction has not persisted yet. We saw that adding a sleep(1) fixes the issue as it gives more time to let the transaction persist.

We previously implemented a timeout to solve this but upon discussions with the database maintainers, upsert was the recommended solution.

How to set up and validate locally

You may refer to the issue on the steps to reproduce locally.

With this fix, doing the podman push ... should work. docker push ... should work as well.

MR acceptance checklist

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

Related to #428115 (closed)

Edited by Adie (she/her)

Merge request reports