@@ -1862,10 +1862,6 @@ def start_queued_workflows(
18621862 sa .select (sa .func .count ())
18631863 .select_from (SystemSchema .workflow_status )
18641864 .where (SystemSchema .workflow_status .c .queue_name == queue .name )
1865- .where (
1866- SystemSchema .workflow_status .c .queue_partition_key
1867- == queue_partition_key
1868- )
18691865 .where (
18701866 SystemSchema .workflow_status .c .status
18711867 != WorkflowStatusString .ENQUEUED .value
@@ -1875,6 +1871,11 @@ def start_queued_workflows(
18751871 > start_time_ms - limiter_period_ms
18761872 )
18771873 )
1874+ if queue_partition_key is not None :
1875+ query = query .where (
1876+ SystemSchema .workflow_status .c .queue_partition_key
1877+ == queue_partition_key
1878+ )
18781879 num_recent_queries = c .execute (query ).fetchone ()[0 ] # type: ignore
18791880 if num_recent_queries >= queue .limiter ["limit" ]:
18801881 return []
@@ -1890,16 +1891,17 @@ def start_queued_workflows(
18901891 )
18911892 .select_from (SystemSchema .workflow_status )
18921893 .where (SystemSchema .workflow_status .c .queue_name == queue .name )
1893- .where (
1894- SystemSchema .workflow_status .c .queue_partition_key
1895- == queue_partition_key
1896- )
18971894 .where (
18981895 SystemSchema .workflow_status .c .status
18991896 == WorkflowStatusString .PENDING .value
19001897 )
19011898 .group_by (SystemSchema .workflow_status .c .executor_id )
19021899 )
1900+ if queue_partition_key is not None :
1901+ pending_tasks_query = pending_tasks_query .where (
1902+ SystemSchema .workflow_status .c .queue_partition_key
1903+ == queue_partition_key
1904+ )
19031905 pending_workflows = c .execute (pending_tasks_query ).fetchall ()
19041906 pending_workflows_dict = {row [0 ]: row [1 ] for row in pending_workflows }
19051907 local_pending_workflows = pending_workflows_dict .get (executor_id , 0 )
@@ -1935,10 +1937,6 @@ def start_queued_workflows(
19351937 )
19361938 .select_from (SystemSchema .workflow_status )
19371939 .where (SystemSchema .workflow_status .c .queue_name == queue .name )
1938- .where (
1939- SystemSchema .workflow_status .c .queue_partition_key
1940- == queue_partition_key
1941- )
19421940 .where (
19431941 SystemSchema .workflow_status .c .status
19441942 == WorkflowStatusString .ENQUEUED .value
@@ -1955,6 +1953,11 @@ def start_queued_workflows(
19551953 # to ensure all processes have a consistent view of the table.
19561954 .with_for_update (skip_locked = skip_locks , nowait = (not skip_locks ))
19571955 )
1956+ if queue_partition_key is not None :
1957+ query = query .where (
1958+ SystemSchema .workflow_status .c .queue_partition_key
1959+ == queue_partition_key
1960+ )
19581961 if queue .priority_enabled :
19591962 query = query .order_by (
19601963 SystemSchema .workflow_status .c .priority .asc (),
0 commit comments