From eb0a06f5ef37123f125c4078f3ae51d2d50c8c01 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Jan 02 2026 18:36:47 +0000
Subject: always prefer task arch in find_arch()


Fixes https://pagure.io/koji/issue/4518

---

diff --git a/builder/kojid b/builder/kojid
index 2f7f948..4e5afc0 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -1647,16 +1647,8 @@ class BuildArchTask(BaseBuildTask):
         rootopts = {
             'repo_id': repo_id
         }
-        if arch == "noarch":
-            # There could have been forced taskarch Exclusive/ExcludeArch,
-            # so we should honor it here.
-            task = self.session.getTaskInfo(self.id)
-            preferred_arch = task['arch']
-        else:
-            preferred_arch = None
         br_arch = self.find_arch(arch, self.session.host.getHost(),
-                                 self.session.getBuildConfig(root, event=event_id),
-                                 preferred_arch=preferred_arch)
+                                 self.session.getBuildConfig(root, event=event_id))
         broot = BuildRoot(self.session, self.options, root, br_arch, self.id, **rootopts)
         broot.workdir = self.workdir
 
diff --git a/koji/tasks.py b/koji/tasks.py
index 189eb2c..c38b35a 100644
--- a/koji/tasks.py
+++ b/koji/tasks.py
@@ -543,6 +543,12 @@ class BaseTaskHandler(object):
         if arch != "noarch":
             return arch
 
+        if preferred_arch is None:
+            task_arch = self.taskinfo['arch']
+            if task_arch != 'noarch':
+                # if a "noarch" task has an arch, the parent has probably overridden
+                preferred_arch = task_arch
+
         # We need a concrete arch. Pick one that:
         #  a) this host can handle
         #  b) the build tag can support
diff --git a/tests/test_lib/test_tasks.py b/tests/test_lib/test_tasks.py
index db1aec9..bc3f062 100644
--- a/tests/test_lib/test_tasks.py
+++ b/tests/test_lib/test_tasks.py
@@ -529,6 +529,7 @@ class TasksTestCase(unittest.TestCase):
         temp_path = self.get_tmp_dir_path('TaskTest')
         makedirs(temp_path)
         obj = TaskTest(123, 'some_method', ['random_arg'], None, None, temp_path)
+        obj._taskinfo = {'arch': 'noarch'}
         self.assertEqual(obj.find_arch('x86_64', None, None), 'x86_64')
 
     def test_BaseTaskHandler_find_arch_noarch_bad_host(self):
@@ -539,6 +540,7 @@ class TasksTestCase(unittest.TestCase):
         makedirs(temp_path)
         host = {'arches': None, 'name': 'test.domain.local'}
         obj = TaskTest(123, 'some_method', ['random_arg'], None, None, temp_path)
+        obj._taskinfo = {'arch': 'noarch'}
         try:
             obj.find_arch('noarch', host, None)
             raise Exception('The BuildError Exception was not raised')
@@ -554,6 +556,7 @@ class TasksTestCase(unittest.TestCase):
         host = {'arches': 'x86_64', 'name': 'test.domain.local'}
         tag = {'arches': None, 'name': 'some_package-1.2-build'}
         obj = TaskTest(123, 'some_method', ['random_arg'], None, None, temp_path)
+        obj._taskinfo = {'arch': 'noarch'}
         try:
             obj.find_arch('noarch', host, tag)
             raise Exception('The BuildError Exception was not raised')
@@ -569,6 +572,7 @@ class TasksTestCase(unittest.TestCase):
         host = {'arches': 'x86_64', 'name': 'test.domain.local'}
         tag = {'arches': 'x86_64 aarch64', 'name': 'some_package-1.2-build'}
         obj = TaskTest(123, 'some_method', ['random_arg'], None, None, temp_path)
+        obj._taskinfo = {'arch': 'noarch'}
         self.assertEqual(obj.find_arch('noarch', host, tag), 'x86_64')
 
     def test_BaseTaskHandler_find_arch__noarch_no_match(self):
@@ -580,6 +584,7 @@ class TasksTestCase(unittest.TestCase):
         host = {'arches': 'i386', 'name': 'test.domain.local'}
         tag = {'arches': 'x86_64 aarch64', 'name': 'some_package-1.2-build'}
         obj = TaskTest(123, 'some_method', ['random_arg'], None, None, temp_path)
+        obj._taskinfo = {'arch': 'noarch'}
         try:
             obj.find_arch('noarch', host, tag)
             raise Exception('The BuildError Exception was not raised')

