Make record_module_build_arches idempotent

This function could get called multiple times if the init handler
runs more than once. This can happen if the build failed in the
init handler due to external infrastructure being down and the
user resumes their build.
This commit is contained in:
mprahl
2020-03-09 16:30:51 -04:00
parent fee1dff8d0
commit 244f29f25f
2 changed files with 6 additions and 1 deletions

View File

@@ -104,7 +104,8 @@ def record_module_build_arches(mmd, build):
arch_obj = db_session.query(models.ModuleArch).filter_by(name=arch).first()
if not arch_obj:
arch_obj = models.ModuleArch(name=arch)
build.arches.append(arch_obj)
if arch_obj not in build.arches:
build.arches.append(arch_obj)
db_session.commit()

View File

@@ -87,6 +87,10 @@ class TestSubmit:
arches = {arch.name for arch in build.arches}
assert arches == set(get_build_arches.return_value)
# Ensure the function is idempotent
record_module_build_arches(build.mmd(), build)
assert len(build.arches) == len(get_build_arches.return_value)
@pytest.mark.parametrize(
"scmurl",
[