Celery: Make psycopg (v3) the default synchronous Postgres driver#69476
Closed
Dev-iL wants to merge 3 commits into
Closed
Celery: Make psycopg (v3) the default synchronous Postgres driver#69476Dev-iL wants to merge 3 commits into
Dev-iL wants to merge 3 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
related:
depends on:
The hardcoded fallback that derives
[celery] result_backendfromsql_alchemy_connwhen a driverlesspostgresql://URL is configured targetedpostgresql+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 targetspostgresql+psycopg://when psycopg (v3) is actually usable, falling back topostgresql+psycopg2://otherwise. A new_USE_PSYCOPG3check (psycopgimportable AND SQLAlchemy ≥ 2.0.0) gates this —providers/celerydeclares 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 todb+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_psycopgasserts the newpostgresql+psycopgscheme (viamonkeypatch.setattr(default_celery, "_USE_PSYCOPG3", True), notimportlib.reload, to stay deterministic regardless of what's actually installed in the test environment). Newtest_result_backend_falls_back_to_psycopg2_without_psycopg3covers the opposite path.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code Sonnet 5 following the guidelines
{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.