Skip to content

Celery: Make psycopg (v3) the default synchronous Postgres driver#69476

Closed
Dev-iL wants to merge 3 commits into
apache:mainfrom
Dev-iL:psycopg3-sync-celery
Closed

Celery: Make psycopg (v3) the default synchronous Postgres driver#69476
Dev-iL wants to merge 3 commits into
apache:mainfrom
Dev-iL:psycopg3-sync-celery

Conversation

@Dev-iL

@Dev-iL Dev-iL commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

related:

depends on:

The hardcoded fallback that derives [celery] result_backend from sql_alchemy_conn when a driverless postgresql:// URL is configured targeted postgresql+psycopg2:// explicitly. Update it to match the new sync Postgres driver default.

What changed

  • providers/celery/src/airflow/providers/celery/executors/default_celery.py: the result-backend URL derivation now targets postgresql+psycopg:// when psycopg (v3) is actually usable, falling back to postgresql+psycopg2:// otherwise. A new _USE_PSYCOPG3 check (psycopg importable AND SQLAlchemy ≥ 2.0.0) gates this — providers/celery declares no dependency on psycopg or SQLAlchemy 2.0, so an unconditional switch would have silently broken the derivation under Airflow's lowest-dependency-resolution CI job.
  • providers/celery/src/airflow/providers/celery/get_provider_info.py: example connection string updated to db+postgresql+psycopg://....
  • providers/celery/docs/changelog.rst: note describing the result-backend URL default change as user-facing.

Test plan

  • providers/celery/tests/unit/celery/executors/test_celery_executor.py: test_result_backend_derived_from_sql_alchemy_conn_uses_psycopg asserts the new postgresql+psycopg scheme (via monkeypatch.setattr(default_celery, "_USE_PSYCOPG3", True), not importlib.reload, to stay deterministic regardless of what's actually installed in the test environment). New test_result_backend_falls_back_to_psycopg2_without_psycopg3 covers the opposite path.
  • Both tests run and pass; deterministic under lowest-dependency-resolution conditions since neither depends on ambient package availability.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code Sonnet 5 following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Dev-iL added 3 commits July 6, 2026 16:39
The hardcoded fallback that derives [celery] result_backend from
sql_alchemy_conn when a driverless postgresql:// URL is configured
targeted postgresql+psycopg2:// explicitly. Update it to
postgresql+psycopg:// to match the sync Postgres driver default change
in apache-airflow and apache-airflow-providers-postgres.

Part of the migration tracked in apache#68453.
The result-backend URL derivation unconditionally targeted
postgresql+psycopg://, but that dialect requires SQLAlchemy 2.0+ and
psycopg installed. providers/celery's own dependency floor is
unbumped, so an environment still on the older combination would have
its result-backend derivation silently start failing on upgrade.
Gate the target scheme on the same psycopg3-availability check
PostgresHook itself uses, falling back to psycopg2 otherwise.
test_result_backend_derived_from_sql_alchemy_conn_uses_psycopg asserted
the psycopg3 scheme unconditionally, but the derivation now depends on
_USE_PSYCOPG3, which reflects whatever happens to be installed. In a
lowest-dependencies environment (providers/celery has no dependency on
psycopg or SQLAlchemy 2.0), this test would deterministically fail
since the code correctly falls back to psycopg2 there. Pin
_USE_PSYCOPG3 explicitly and call get_default_celery_config directly,
matching the fallback test added alongside it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant