xchwan commented on issue #73714:
URL: https://github.com/apache/airflow/issues/73714#issuecomment-7023338886
Hi @kaxil, I looked into the history of this issue and wanted to check which
direction you'd prefer before opening anything.
**The bug**
`merge_dicts` (`airflow/utils/helpers.py`) recurses when dict2's value is a
dict without checking that dict1's value is also a dict. It is still unchanged
on `main`:
if k in merged and isinstance(v, dict):
merged[k] = merge_dicts(merged.get(k, {}), v)
**History**
Three PRs made the same change and none was merged:
- #70349: opened 2026-07-24, no reviews, closed by the stale bot on
2026-11-04.
- #70457: opened 2026-07-26, parametrized test over
`str`/`list`/`None`/`int`, closed on 2026-10-01 in favor of #70349.
- #73718: opened 2026-09-25, closed on 2026-10-01 since the other two
already had the same guard.
The change: recurse only when both values are dicts, otherwise let dict2's
value overwrite, as the docstring says ("Items in dict2 overwrite those also
found in dict1"). No review comment on any of them objected to it, but #70349
was closed without a review.
**What I checked**
I ran every caller of `merge_dicts` in the repo against both `main` and the
change (calling the real methods, 7-10 scenarios each):
- `json_formatter`, ECS executor, Batch executor, HTTP operator, Vault hook,
ODBC hook: every case that raised `AttributeError`/`TypeError` before (a dict
over a str/int/bool/`None`/list) now overwrites. Normal dict merges, new keys,
scalar over scalar, and a dict replaced by a scalar or `None` give identical
results.
- `gcs_to_bigquery`, `bigquery_to_gcs` and the common SQL operator merge
OpenLineage facet objects, not dicts (checked with the real classes and
`get_facets_from_bq_table`), so results are identical before and after.
- The existing tests of each caller give the same results with and without
the change (the failures I saw locally are identical on `main`).
**One behavior change beyond the crash fix, and why I think it is
reasonable**
When dict2's value is an empty dict `{}` and dict1's value is a list, `main`
silently kept the list; with the change the list is overwritten by `{}`:
- ECS `exec_config` `containerOverrides: {}`: previously ignored, now
`KeyError: No such container found ...`.
- Batch `exec_config` `containerOverrides.environment: {}`: previously
ignored, now `AttributeError: 'dict' object has no attribute 'append'`.
- HTTP pagination `data` (nested): `{"a": [1]}` with `{"a": {}}` previously
stayed `[1]`, now becomes `{}`.
Why I think this is the right behavior:
1. The old result was accidental. For an empty dict, the recursive call
loops zero times and returns `list.copy()`; for a non-empty dict over the same
list it raises `TypeError`. So `main` ignored `{}` but crashed on `{"a": 1}`,
and `{}` over a str/int/`None` also raised. Nothing in the code or docs
describes "ignore an empty dict".
2. It matches what is documented. The docstring says dict2 overwrites; the
ECS docs describe `exec_config` as `run_task_kwargs.update(exec_config)`
applied recursively; `HttpOperator._merge_next_page_parameters` says items in
`next_page_params` override the previous request.
3. It is consistent with the other direction. A scalar over a dict already
overwrites on `main` and in the tests of the three PRs, so every type mismatch
now behaves the same way.
4. Every case requires passing `{}` where a list is expected, i.e. an
invalid value for that field. For ECS the task then fails with an explicit
error (the executor catches it, retries, and marks the task failed with the
reason) instead of silently running with defaults that ignore what the user
configured.
The trade-offs: the Batch error message is not very clear, and the HTTP case
changes the request payload without an error. I did not change them here; any
validation of those fields would belong in the executors/operator, not in this
helper. I also found no use of `MappingProxyType` in `airflow-core`, `task-sdk`
or the providers above (a non-dict `Mapping` on the left is merged by `main`
but overwritten with the change).
Would you prefer reopening #70349, or is a fresh PR with the same guard and
a parametrized test (without a newsfragment) fine?
---
Drafted-by: Claude Code (Sonnet 5.5); reviewed by @xchwan 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]