From: Michael Tremer Date: Thu, 6 Feb 2025 17:52:58 +0000 (+0000) Subject: jobs: Associate imported packages with the job X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d24c7c39a00c1abdbe4267ba1d9cc734bb908f03;p=pbs.git jobs: Associate imported packages with the job Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index a34d0799..57e757ef 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -486,29 +486,27 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin): """ Will take a list of uploads and import them as packages """ + packages = [] + # Do not allow importing any packages for test builds if self.is_test(): raise RuntimeError("Cannot import packages for test builds") - packages = [] - # Import all packages for upload in uploads: - package = await self.backend.packages.create(upload) - packages.append(package) - - # Add them to the database - self.db.executemany(""" - INSERT INTO - job_packages( - job_id, - pkg_id - ) - VALUES( - %s, %s - )""", ( - (self.id, package.id) for package in packages + packages.append( + await self.backend.packages.create(upload), ) + + # Flush the packages to the database + await self.db.flush() + + # Associate the packages with this job + await self.db.insert_many( + JobPackage, ({ + "job_id" : self.id, + "pkg_id" : pkg.id, + } for pkg in packages), ) # Consume all packages