Skip to content

Conversation

@desertaxle
Copy link
Member

@desertaxle desertaxle commented Jan 9, 2026

Related to #15008

This PR is needed for the Custom Deployment SDK feature (see plans/2026-01-06-custom-deployment-sdks.md).

Summary

  • Add arun_deployment as an explicit async function for running deployments
  • Replace @sync_compatible with @async_dispatch on run_deployment
  • run_deployment now automatically dispatches to arun_deployment in async context
  • Sync context uses SyncPrefectClient directly (no event loop magic)
  • Export arun_deployment from prefect.deployments

Changes

The run_deployment function now uses the @async_dispatch pattern instead of @sync_compatible:

# Async context - dispatches to arun_deployment
async def my_flow():
    flow_run = await run_deployment("my-flow/my-deployment")

# Sync context - runs synchronously with SyncPrefectClient
def my_sync_code():
    flow_run = run_deployment("my-flow/my-deployment")

# Explicit async - can also call arun_deployment directly
async def explicit_async():
    flow_run = await arun_deployment("my-flow/my-deployment")

Backward Compatibility

  • The run_deployment signature is maintained
  • The run_deployment.aio attribute is preserved, pointing to arun_deployment
  • All existing tests continue to pass

🤖 Generated with Claude Code

This change follows the intent of issue #15008 to replace implicit
sync/async conversion with explicit, type-safe alternatives.

Changes:
- Add `arun_deployment` as an explicit async function for running deployments
- Replace `@sync_compatible` with `@async_dispatch` on `run_deployment`
- `run_deployment` now dispatches to `arun_deployment` in async context
- Sync context uses `SyncPrefectClient` directly (no event loop magic)
- Export `arun_deployment` from `prefect.deployments`
- Add comprehensive tests for both sync and async behavior

The `run_deployment.aio` attribute is preserved for backward compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@desertaxle desertaxle force-pushed the add-arun-deployment-async-dispatch branch from 7b33c4c to 59b731d Compare January 9, 2026 21:46
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 9, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing add-arun-deployment-async-dispatch (86f3a7c) with main (06750f7)

Summary

✅ 2 untouched benchmarks

@desertaxle desertaxle marked this pull request as ready for review January 9, 2026 22:00
@desertaxle desertaxle changed the title Add arun_deployment and replace sync_compatible with async_dispatch Add arun_deployment and replace @sync_compatible with @async_dispatch Jan 9, 2026
@desertaxle desertaxle added the development Tech debt, refactors, CI, tests, and other related work. label Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development Tech debt, refactors, CI, tests, and other related work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants