Eason09053360 opened a new pull request, #70944:
URL: https://github.com/apache/airflow/pull/70944
`airflow variables export` followed by `airflow variables import` can
silently rewrite a variable's value and invent a description for it.
Export writes a bare value when a variable has no description, while import
treats any dict carrying a `"value"` key as a `{"value": ..., "description":
...}` envelope — nothing distinguishes the envelope from a value that happens
to look like one. Export also decodes the stored JSON, losing the difference
between raw text and a JSON-encoded string.
Round-tripping through a file on `main` :
| DB value before | exported as | after re-import |
|---|---|---|
| `{"value": "a", "description": "b"}` | `{"value": "a", "description":
"b"}` | value → `a`, description → `b` |
| `{"value": 1, "other": 2}` | `{"value": 1, "other": 2}` | value → `1`,
`other` dropped |
| `"hello"` | `hello` | `hello` — no longer valid JSON, so
`deserialize_json=True` starts raising |
Import's reconstruction is deterministic — strings are stored verbatim,
everything else is JSON-encoded, and one envelope layer is unwrapped — so
export alone can be made lossless, leaving hand-written import files behaving
exactly as before. Export now emits the stored form when the decoded value is a
string, and wraps values that are themselves envelope-shaped so import's unwrap
consumes our envelope rather than the user's data.
Exported files are unchanged for values that were never ambiguous. One
visible change worth flagging: a variable stored as a JSON-encoded string
(`Variable.set(k, "text", serialize_json=True)`) now exports as `"\"text\""`
rather than `"text"`. The old output could not be re-imported without
corruption, so there is no lossless way to keep it.
Left for follow-up PRs: import still truncates a hand-written `{"value": 1,
"other": 2}` to `1`, and the UI import path does not unwrap the envelope at all.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]