Skip to content

feat(worker): add --no-create-pool-if-not-found flag to worker start#21004

Open
VittoriaLanzo wants to merge 2 commits intoPrefectHQ:mainfrom
VittoriaLanzo:fix/20980-no-create-pool-if-not-found
Open

feat(worker): add --no-create-pool-if-not-found flag to worker start#21004
VittoriaLanzo wants to merge 2 commits intoPrefectHQ:mainfrom
VittoriaLanzo:fix/20980-no-create-pool-if-not-found

Conversation

@VittoriaLanzo
Copy link

Summary

Resolves #20980.

The BaseWorker.__init__ already accepts a create_pool_if_not_found kwarg that prevents the worker from auto-creating the work pool when it doesn't exist. This is useful when the work pool is managed externally by Terraform, Pulumi, or another provisioning tool — the worker should fail fast (or wait) rather than silently re-creating the pool.

However, there was no way to pass this flag from the CLI. This PR exposes it as a --create-pool-if-not-found / --no-create-pool-if-not-found flag on prefect worker start.

Changes

  • Added create_pool_if_not_found: bool = True parameter to the start command in src/prefect/cli/worker.py
  • Passed the value through to worker_cls(..., create_pool_if_not_found=create_pool_if_not_found)

Usage

# Default behaviour (unchanged)
prefect worker start --pool my-pool

# Prevent auto-creation — worker will error if pool doesn't exist
prefect worker start --pool my-pool --no-create-pool-if-not-found

Exposes the existing BaseWorker.create_pool_if_not_found kwarg via the
CLI so users who manage work pools externally (e.g. via Terraform, Pulumi
or a custom provisioning script) can prevent the worker from re-creating
the pool if it is absent.

Closes PrefectHQ#20980
@github-actions github-actions bot added enhancement An improvement of an existing feature labels Mar 6, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 6, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing VittoriaLanzo:fix/20980-no-create-pool-if-not-found (f0262df) with main (5a8ca70)

Open in CodSpeed

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VittoriaLanzo, you'll need to update some of the existing tests to pass the CI checks. Please make sure to add at least one test that covers this new functionality as well.

@VittoriaLanzo
Copy link
Author

Thanks for the review @desertaxle!
Done:
∙ Updated all 6 existing mock_worker.assert_called_once_with() assertions to include create_pool_if_not_found=True (the default), matching the new kwarg passed through to worker_cls in the CLI
∙ Added test_start_worker_with_no_create_pool_if_not_found: invokes the CLI with the negative flag and asserts create_pool_if_not_found=False is passed to the worker constructor
All 26 tests in tests/cli/test_worker.py pass locally.
One heads-up: because the cyclopts Parameter name was given as a single string "--create-pool-if-not-found/--no-create-pool-if-not-found" rather than using the negative= kwarg, cyclopts treats the whole string as one flag name and auto-generates the negative as --no-create-pool-if-not-found/--no-create-pool-if-not-found. The test uses that generated name. If you’d prefer users to be able to type --no-create-pool-if-not-found directly, changing the src/ definition to Parameter("--create-pool-if-not-found", negative="--no-create-pool-if-not-found", ...) would fix it — happy to make that change.

…found flag

Fix the 5 failing "Runner, Worker, Settings, Input, and CLI Tests" CI checks.

The new create_pool_if_not_found kwarg added in the previous commit is now
passed to worker_cls(...), but 6 existing mock-based tests asserted the call
signature without it, causing strict assert_called_once_with() failures.

Changes:
- Add create_pool_if_not_found=True to all 6 existing mock_worker.assert_called_once_with() calls
- Add test_start_worker_create_pool_if_not_found_default: verifies the flag defaults to True
- Add test_start_worker_no_create_pool_if_not_found: verifies --no-create-pool-if-not-found passes False
VittoriaLanzo pushed a commit to VittoriaLanzo/sestara that referenced this pull request Mar 7, 2026
… flag

Add create_pool_if_not_found=True to all six existing mock_worker
assert_called_once_with() calls in tests/cli/test_worker.py, and add two
new tests covering the default (True) and explicit --no-create-pool-if-not-found
(False) behaviors.

Addresses CI failures flagged by @desertaxle on PrefectHQ/prefect#21004.

https://claude.ai/code/session_01B9vDLAYgy3rDoVEa5rwZhi
VittoriaLanzo pushed a commit to VittoriaLanzo/prefect that referenced this pull request Mar 7, 2026
…ectHQ#21004

Implements the create_pool_if_not_found boolean CLI flag on the worker
start() command using the correct cyclopts negative= parameter syntax
(instead of the typer-style slash notation from the PR).

Updates all existing tests that assert on worker_cls() constructor kwargs
to include create_pool_if_not_found=True (the default), and adds two new
tests covering default behavior and the --no-create-pool-if-not-found flag.

https://claude.ai/code/session_01ENHt9FzX43ecFSrPTwA6Q9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disable Auto Work Pool Creation

3 participants