You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "potiuk (via GitHub)" <gi...@apache.org> on 2026/07/29 21:10:48 UTC
[PR] Do not import the stored path when rebuilding a Callback from serialized data [airflow]
potiuk opened a new pull request, #70704:
URL: https://github.com/apache/airflow/pull/70704
`Callback.get_callback_path` imports the module named by a dotted-path string in
order to check that it resolves to a callable. That check is deliberately best
effort — the `ImportError` is logged and swallowed and the path is returned
either way, because the callable may only exist on the host that will eventually
run it.
Rebuilding a `Callback` from its serialized form went through that same path, so
deserializing one imported the module named in the stored data. The path was
already checked when the `Callback` was first created, and reconstruction happens
in components that never invoke the callback themselves, so importing there is
neither needed nor wanted — it runs module-level code of whatever the stored
string happens to name.
This carries a path read back from serialized data in a private `str` subclass
and returns it unchanged instead of resolving it a second time.
Construction from a Dag author's callable or dotted path is unaffected, including
the existing import-based callable check. The dot-path shape check still applies
to stored paths too, so a malformed stored path is still rejected.
### Test plan
- [x] `test_init_imports_the_module_named_by_the_path` — positive control: Dag-author construction still resolves the path
- [x] `test_deserialize_does_not_import_the_module_named_by_the_stored_path` — and the `AsyncCallback` equivalent
- [x] `test_serde_deserialize_does_not_import_the_module_named_by_the_stored_path` — full route through serde
- [x] `test_deserialize_rejects_a_path_which_is_not_a_dot_path` — shape check preserved on stored paths
- [x] `test_deserialize_keeps_a_stored_path_which_no_longer_points_at_a_callable`
- [x] Tests use a real fixture module whose import has an observable side effect, rather than mocking `import_string`
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Opus 5 (1M context)
Generated-by: Claude Opus 5 (1M context) following the guidelines at
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not import the stored path when rebuilding a Callback from serialized data [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #70704:
URL: https://github.com/apache/airflow/pull/70704
--
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] Do not import the stored path when rebuilding a Callback from serialized data [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #70704:
URL: https://github.com/apache/airflow/pull/70704#discussion_r3701658145
##########
task-sdk/src/airflow/sdk/definitions/callback.py:
##########
@@ -66,6 +80,14 @@ def get_callback_path(cls, _callback: str | Callable) -> str:
stripped_callback = _callback.strip()
+ if isinstance(_callback, _SerializedCallbackPath):
+ # This path was already checked when the Callback it belongs to was created, so
+ # rebuilding that Callback keeps it as it is. Reconstruction happens in components
+ # which never call the callback themselves, and resolving the path there is neither
+ # needed nor wanted: the module it names is not necessarily importable in that
+ # process, and importing it has no bearing on the path we return either way.
+ return stripped_callback
Review Comment:
Both the docstring and usage almost narrate the same thing, suggest removing in one of them
--
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] Do not import the stored path when rebuilding a Callback from serialized data [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #70704:
URL: https://github.com/apache/airflow/pull/70704#discussion_r3708428050
##########
task-sdk/src/airflow/sdk/definitions/callback.py:
##########
@@ -66,6 +80,14 @@ def get_callback_path(cls, _callback: str | Callable) -> str:
stripped_callback = _callback.strip()
+ if isinstance(_callback, _SerializedCallbackPath):
+ # This path was already checked when the Callback it belongs to was created, so
+ # rebuilding that Callback keeps it as it is. Reconstruction happens in components
+ # which never call the callback themselves, and resolving the path there is neither
+ # needed nor wanted: the module it names is not necessarily importable in that
+ # process, and importing it has no bearing on the path we return either way.
+ return stripped_callback
Review Comment:
Right — it was narrated three times: the class docstring, the branch in `get_callback_path`, and again in `deserialize`. Kept it at `get_callback_path`, where the decision is actually made and where the non-obvious part lives (the module named by a stored path is not necessarily importable in the process doing the reconstruction). The class docstring is now one line pointing there, and the `deserialize` comment is gone.
---
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] Do not import the stored path when rebuilding a Callback from serialized data [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #70704:
URL: https://github.com/apache/airflow/pull/70704#issuecomment-5173425434
### Backport successfully created: v3-3-test
Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>✅</td>
<td>v3-3-test</td>
<td><a href="https://github.com/apache/airflow/pull/71042"><img src="https://img.shields.io/badge/PR-71042-blue" alt="PR Link"></a></td>
</tr>
</table>
--
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