Bug 11717

Summary: large package set causes 'too many SQL variables' error
Product: [Build System, Metadata & Runtime] Toaster Reporter: David Reyna <david.reyna>
Component: toasterAssignee: David Reyna <david.reyna>
Status: RESOLVED FIXED QA Contact: Libertad <libertad.gonzalez.de.la.cruz>
Severity: normal    
Priority: Medium+ CC: jessica.zhang, stanciux.mihail
Version: 2.4   
Target Milestone: 2.4 M2   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description David Reyna 2017-06-24 05:21:04 UTC
If you build a project with a large package set, you will get a crash in "views.py" when the dashboard attempts to fetch the package set to calculate the package count and size.

This is a sqlite limitation, and it fails with as few as 1220 packages.

To reproduce, build the "intelx86-64" machine using the intel-x86 layer, and then try to bring up the build's dashboard page.
Comment 1 David Reyna 2017-06-24 05:22:17 UTC
The solution is to break the query into parts.

diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 2efb0fd5..39014379 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -483,10 +483,15 @@ def builddashboard( request, build_id ):
         npkg = 0
         pkgsz = 0
         package = None
-        for package in Package.objects.filter(id__in = [x.package_id for x in t.target_installed_package_set.all()]):
-            pkgsz = pkgsz + package.size
-            if package.installed_name:
-                npkg = npkg + 1
+        # Chunk the query to avoid "too many SQL variables" error
+        package_set = t.target_installed_package_set.all()
+        package_set_len = len(package_set)
+        for ps_start in range(0,package_set_len,500):
+            ps_stop = min(ps_start+500,package_set_len)
+            for package in Package.objects.filter(id__in = [x.package_id for x in package_set[ps_start:ps_stop]]):
+                pkgsz = pkgsz + package.size
+                if package.installed_name:
+                    npkg = npkg + 1
         elem['npkg'] = npkg
         elem['pkgsz'] = pkgsz
Comment 2 David Reyna 2017-07-12 15:28:10 UTC
commit eea5cb317137d71ad0cab954d2c9ad2069580b6f