vishalmore90 opened a new pull request, #76977:
URL: https://github.com/apache/airflow/pull/76977
### Description
This PR resolves an unhandled `TypeError` in `Callback.__hash__` and
`DeadlineAlert.__hash__` when a callback is defined with collection or nested
arguments in `kwargs`.
`Callback.serialize()` is JSON-serializable by specification (persisted to a
database JSON column). Previously, `Callback.__hash__` attempted to make
`kwargs` hashable by only flattening the top level via
`tuple(sorted(v.items()))`. If any value inside `kwargs` was a `list` or a
nested `dict` (e.g. `kwargs={"recipients": ["[email protected]"]}` or
`kwargs={"config": {"timeout": 30}}`), Python raised `TypeError: unhashable
type: 'list'` or `'dict'`.
Furthermore, because `DeadlineAlert.__hash__` delegates to
`hash(self.callback)`, hashing `DeadlineAlert` instances or inserting them into
a `set` (e.g. for Dag deadline alert deduplication) also crashed.
This change hashes a canonical sorted JSON string representation
(`json.dumps(self.serialize(), sort_keys=True, default=str)`), which:
1. Recursively handles arbitrary nested lists, dicts, primitives, and nulls.
2. Guarantees key-order independence via `sort_keys=True` so `callback1 ==
callback2` $\implies$ `hash(callback1) == hash(callback2)`.
3. Adds unit tests covering lists, nested dicts, and key-ordering variations
for both `Callback` and `DeadlineAlert`.
closes: #76973
---
##### Was generative AI tooling used to co-author this PR?
- [x] Yes (Antigravity)
Generated-by: Antigravity 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]