You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Eason09053360 (via GitHub)" <gi...@apache.org> on 2026/09/13 14:44:01 UTC
[PR] Fix airflow connections import corrupting JSON values in .env files [airflow]
Eason09053360 opened a new pull request, #73083:
URL: https://github.com/apache/airflow/pull/73083
## Why
`airflow connections export --file-format env --serialization-format json` writes a file that
`airflow connections import` cannot read back. In `_create_connection`, a string value from a
`.env` file was always treated as a URI, and `urlsplit()` never rejects anything, so the JSON
payload was parsed as a path: `conn_type`, `host`, `login` and `port` came out empty and the rest
of the JSON blob landed in the `schema` column. The command printed `Imported connection <id>` and
exited 0, so the corruption is silent until a task fails to connect.
```console
$ airflow connections export conns.env --file-format env --serialization-format json
$ airflow connections import conns.env
Imported connection my_conn
```
| | conn_type | host | login | port | schema |
|---|---|---|---|---|---|
| before | *(empty)* | *(empty)* | *(empty)* | *(empty)* | `"conn_type": "mysql", ... }` |
| after | mysql | myhost | mylogin | 3306 | mysch |
That value is the same string one would put in `AIRFLOW_CONN_*`, and every other secrets backend
already accepts both forms there: `BaseSecretsBackend._deserialize_connection_value` treats a
`{`-prefixed value as JSON and anything else as a URI. `local_filesystem` was the only backend
missing that test.
## What
- `airflow-core/src/airflow/secrets/local_filesystem.py`: a `{`-prefixed string value is
deserialized with `Connection.from_json()` instead of being parsed as a URI. A URI can never
start with `{` (RFC 3986 requires the scheme to begin with a letter), so the two forms are
unambiguous and existing URI files are untouched. Going through `from_json()` rather than this
module's object branch also keeps `.env` values consistent with `AIRFLOW_CONN_*` for `conn_type`
normalization and `port` coercion. Malformed JSON, which previously produced a garbage
connection, now raises a `ValueError` naming the connection.
- `airflow-core/docs/security/secrets/secrets-backend/local-filesystem-secrets-backend.rst`:
document that a `.env` value may be a URI or a JSON object.
- Tests: `test_cli_connections_import_should_round_trip_env_file_exported_as_json` covers the
reported export/import path;
`test_env_file_json_connection_is_normalized_like_an_environment_variable` pins the
`postgresql` -> `postgres` and `"5432"` -> `5432` parity with the environment variable backend.
`.json` and `.yaml` files still go through this module's object branch, which does not normalize
`conn_type` or coerce `port`. That predates this change and is left alone here — happy to follow
up separately if reviewers want the two paths unified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix airflow connections import corrupting JSON values in .env files [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #73083:
URL: https://github.com/apache/airflow/pull/73083#issuecomment-5839074718
Hello @Eason09053360 - thank you for your contributions to Apache Airflow!
The Airflow community has introduced a limit of **5 open pull requests at a time** for contributors without write access to the repository. You currently have 33 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
* #70935 - Return only the latest Dag version from iter_all_latest_version_dags
* #72145 - Fix airflow config get-value silently succeeding on a missing option
* #72468 - Fix airflowctl tracebacks on an unusable credentials file
* #72600 - Make suppress_logs_and_warning CLI decorator return the wrapped result
* #72656 - Fix dateless dag.test and tasks test destroying unrelated Dag runs
* #72675 - Fix airflowctl commands crashing instead of printing their result
* #72893 - Show a clean error when airflow backfill create targets an unknown Dag
* #72941 - Fix tasks clear --task-regex matching as a plain substring
* #73033 - Speed up airflow dags list on deployments with many Dags
* #73070 - Fix airflow dags next-execution crashing on --field data_interval.start
* #73083 - Fix airflow connections import corrupting JSON values in .env files
* #73112 - Fix structlog log assertions never matching a single-field dict
* #73120 - Fix misleading type errors from expand_kwargs and default_args
* #73121 - Fix bare traceback from kubernetes cleanup-pods without kube config
* #73132 - Fix airflowctl pools export/import dropping pool team ownership
* #73157 - Mask extra and credentials in connections list --hide-sensitive
* #73228 - Fix missing task alert emails on Dags using native template rendering
* #73348 - Stop providers lazy-loaded from writing the default config
* #73371 - Fix api-server --apps silently dropping apps and accepting typos
* #73373 - Fix Task SDK dry-run mode crashing on task instance start
* #73377 - Fix CLI --bundle-name finding no Dags in Git bundles
* #73379 - Fix empty audit log dag_id for DAG.cli() subcommands
* #73387 - Drop ignored --bundle-name and --dagfile-path from DAG.cli()
* #73400 - Fix indexing mapped task results with a NumPy integer
* #73409 - Respect maximum_page_limit in batch list endpoints
* #73422 - Stop the JWT revocation check stalling the API server event loop
* #73424 - Fix task instance 404 detail being a JSON array instead of a string
* #73463 - API: Remove unreachable Accept branch and last deprecated 422 alias
* #73465 - API: Cap run_ids on the grid TI summaries stream endpoint
* #73472 - Rate-limit JWKS fetch attempts while the endpoint is down
* #73514 - UI: Fix grid columns vanishing when a Dag version has been cleaned
These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
* #73141 - Fix scheduler refusing to start when [scheduler] only_idle is enabled
* #73154 - Batch Team lookups when syncing Dag bundles to the database
This is **not** a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.
What we ask you to do is to make your **first prioritization decision**: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or `gh pr reopen <PR_NUMBER> --repo apache/airflow`. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.
While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.
Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.
---
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix airflow connections import corrupting JSON values in .env files [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed pull request #73083: Fix airflow connections import corrupting JSON values in .env files
URL: https://github.com/apache/airflow/pull/73083
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix airflow connections import corrupting JSON values in .env files [airflow]
Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on code in PR #73083:
URL: https://github.com/apache/airflow/pull/73083#discussion_r4002487886
##########
airflow-core/src/airflow/secrets/local_filesystem.py:
##########
@@ -198,6 +198,13 @@ def _create_connection(conn_id: str, value: Any):
from airflow.models.connection import Connection
if isinstance(value, str):
+ # A URI can never start with "{" (RFC 3986: the scheme begins with a letter), and a ``.env``
+ # value is the string one would put in ``AIRFLOW_CONN_*`` -- so JSON deserializes as it does there.
+ if value.lstrip().startswith("{"):
Review Comment:
This reimplements the { test instead of calling BaseSecretsBackend._deserialize_connection_value. The helper does value.strip() then value[0] == "{"; this lstrip()s only for the check, then passes the original string.
Also not dotenv: quoted CONN_ID='{"conn_type":...}' still fails the { test and still corrupts. Export does not quote, so the reported path is fine. Hand-written .env files that quote JSON still die the old way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix airflow connections import corrupting JSON values in .env files [airflow]
Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on code in PR #73083:
URL: https://github.com/apache/airflow/pull/73083#discussion_r4002487886
##########
airflow-core/src/airflow/secrets/local_filesystem.py:
##########
@@ -198,6 +198,13 @@ def _create_connection(conn_id: str, value: Any):
from airflow.models.connection import Connection
if isinstance(value, str):
+ # A URI can never start with "{" (RFC 3986: the scheme begins with a letter), and a ``.env``
+ # value is the string one would put in ``AIRFLOW_CONN_*`` -- so JSON deserializes as it does there.
+ if value.lstrip().startswith("{"):
Review Comment:
This reimplements the { test instead of calling BaseSecretsBackend._deserialize_connection_value. The helper does value.strip() then value[0] == "{"; this lstrip()s only for the check, then passes the original string.
Also not dotenv: quoted CONN_ID='{"conn_type":...}' still fails the { test and still corrupts. Export does not quote, so the reported path is fine. Hand-written .env files that quote JSON still die the old way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org