Index: trunk/ippTools/share/disttool_pendingcomponent.sql
===================================================================
--- trunk/ippTools/share/disttool_pendingcomponent.sql	(revision 23566)
+++ trunk/ippTools/share/disttool_pendingcomponent.sql	(revision 23661)
@@ -16,14 +16,16 @@
 FROM distRun
 JOIN rawExp ON exp_id = stage_id
-JOIN (                      -- find the last magicked chip run 
+JOIN (                      -- find the last satisfactory chip run 
+                            -- note this requires that a chip run have been completed even when 
+                            -- magic is not required for the run
     SELECT
         exp_id,
         MAX(chip_id) AS chip_id
     FROM chipRun
+    JOIN distRun ON stage_id = exp_id AND stage = 'raw'
     WHERE 
         chipRun.state = 'full'
         AND chipRun.exp_id = exp_id
-        --   AND chipRun.magicked
-        -- magicked hook 1 %s
+        AND (chipRun.magicked OR distRun.no_magic)
         GROUP BY exp_id
     ) AS bestChipRun 
@@ -39,5 +41,5 @@
     AND distRun.stage = 'raw'
     AND distComponent.dist_id IS NULL
-    -- if magicked add AND rawImfile.magicked here
+    AND (rawExp.magicked OR distRun.no_magic)
     -- where hook 1 %s
 
@@ -69,4 +71,5 @@
     AND distRun.stage = 'chip'
     AND distComponent.dist_id IS NULL
+    AND (distRun.clean OR chipRun.magicked OR distRun.no_magic)
     -- where hook 2 %s
 UNION
@@ -98,4 +101,5 @@
     AND distRun.stage = 'camera'
     AND distComponent.dist_id IS NULL
+    AND (distRun.clean OR chipRun.magicked OR distRun.no_magic)
     -- where hook 3 %s
 UNION
@@ -157,4 +161,5 @@
     AND distRun.stage = 'warp'
     AND distComponent.dist_id IS NULL
+    AND (distRun.clean OR warpRun.magicked OR distRun.no_magic)
     -- where hook 5 %s
 UNION
@@ -186,4 +191,5 @@
     AND distRun.stage = 'diff'
     AND distComponent.dist_id IS NULL
+    AND (distRun.clean OR diffRun.magicked OR distRun.no_magic)
     -- where hook 6 %s
 UNION
