mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 11:48:33 +08:00
Don't try to add duplicate buildrequires entries when importing a module
To do this, we need to use the same database session in import_mmd as in ModuleBuild.get_buildrequired_base_modules, otherwise, the returned ModuleBuild objects are in a detached state.
This commit is contained in:
@@ -682,7 +682,7 @@ class ModuleBuild(MBSBase):
|
||||
module.module_builds_trace.append(mbt)
|
||||
|
||||
# Record the base modules this module buildrequires
|
||||
for base_module in module.get_buildrequired_base_modules():
|
||||
for base_module in module.get_buildrequired_base_modules(session):
|
||||
module.buildrequires.append(base_module)
|
||||
|
||||
session.add(module)
|
||||
@@ -963,10 +963,11 @@ class ModuleBuild(MBSBase):
|
||||
|
||||
return result
|
||||
|
||||
def get_buildrequired_base_modules(self):
|
||||
def get_buildrequired_base_modules(self, session):
|
||||
"""
|
||||
Find the base modules in the modulemd's xmd section.
|
||||
|
||||
:param session: the SQLAlchemy database session to use to query
|
||||
:return: a list of ModuleBuild objects of the base modules that are buildrequired with the
|
||||
ordering in conf.base_module_names preserved
|
||||
:rtype: list
|
||||
@@ -974,25 +975,24 @@ class ModuleBuild(MBSBase):
|
||||
"""
|
||||
rv = []
|
||||
xmd = self.mmd().get_xmd()
|
||||
with make_session(conf) as db_session:
|
||||
for bm in conf.base_module_names:
|
||||
try:
|
||||
bm_dict = xmd["mbs"]["buildrequires"].get(bm)
|
||||
except KeyError:
|
||||
raise RuntimeError("The module's mmd is missing information in the xmd section")
|
||||
for bm in conf.base_module_names:
|
||||
try:
|
||||
bm_dict = xmd["mbs"]["buildrequires"].get(bm)
|
||||
except KeyError:
|
||||
raise RuntimeError("The module's mmd is missing information in the xmd section")
|
||||
|
||||
if not bm_dict:
|
||||
continue
|
||||
base_module = self.get_build_from_nsvc(
|
||||
db_session, bm, bm_dict["stream"], bm_dict["version"], bm_dict["context"]
|
||||
if not bm_dict:
|
||||
continue
|
||||
base_module = self.get_build_from_nsvc(
|
||||
session, bm, bm_dict["stream"], bm_dict["version"], bm_dict["context"]
|
||||
)
|
||||
if not base_module:
|
||||
log.error(
|
||||
'Module #{} buildrequires "{}" but it wasn\'t found in the database'.format(
|
||||
self.id, repr(bm_dict))
|
||||
)
|
||||
if not base_module:
|
||||
log.error(
|
||||
'Module #{} buildrequires "{}" but it wasn\'t found in the database'.format(
|
||||
self.id, repr(bm_dict))
|
||||
)
|
||||
continue
|
||||
rv.append(base_module)
|
||||
continue
|
||||
rv.append(base_module)
|
||||
|
||||
return rv
|
||||
|
||||
|
||||
@@ -517,8 +517,9 @@ def import_mmd(session, mmd, check_buildrequires=True):
|
||||
|
||||
# Record the base modules this module buildrequires
|
||||
if check_buildrequires:
|
||||
for base_module in build.get_buildrequired_base_modules():
|
||||
build.buildrequires.append(base_module)
|
||||
for base_module in build.get_buildrequired_base_modules(session):
|
||||
if base_module not in build.buildrequires:
|
||||
build.buildrequires.append(base_module)
|
||||
|
||||
session.add(build)
|
||||
session.commit()
|
||||
|
||||
Reference in New Issue
Block a user