Abolfazlrwm commented on code in PR #76627:
URL: https://github.com/apache/airflow/pull/76627#discussion_r4651919428
##########
ts-sdk/src/generated/dag-schema-fields.ts:
##########
@@ -212,4 +212,4 @@ export const TASK_SCHEMA_FIELDS = {
/** The `__version` the serializer stamps into a serialized Dag. The schema
* constrains it only to a positive integer, so it is pinned here and guarded
* by a test in airflow-core. */
-export const SERIALIZATION_VERSION = 3;
+export const SERIALIZATION_VERSION = 4;
Review Comment:
Fixed in `c54c467` — the pinning test had not moved with the generator. It
now expects `4`. The cross-check that catches this class of drift,
`airflow-core/tests/unit/serialization/test_ts_sdk_serialization_version.py`,
compares the generated file against `DagSerialization.SERIALIZER_VERSION`, so
the two sides can no longer disagree silently.
##########
ts-sdk/scripts/generate-dag-schema.mjs:
##########
@@ -83,7 +83,7 @@ const OUT_PATH = join(ROOT,
"src/generated/dag-schema-fields.ts");
* and
`airflow-core/tests/unit/serialization/test_ts_sdk_serialization_version.py`
* fails until it is.
*/
-export const SERIALIZATION_VERSION = 3;
+export const SERIALIZATION_VERSION = 4;
Review Comment:
No — and that is deliberate. Core's `from_dict` raises `ValueError: Unsure
how to deserialize version 4` for any version it does not know: versions are
explicit and upgraded through conversion functions (v1→v2→v3→v4), so Airflow
3.4.0, which tops out at 3, rejects a bundle stamped 4 at deserialization
instead of silently misreading it.
The bundle is generated from *this* version's schema, and 4 is exactly what
this core writes — `DagSerialization` now stamps `__version: 4` and carries
`conversion_v3_to_v4` for the new `static_url` entries. A 3.4.0 core could not
interpret those entries anyway (it has no static-url semantics), so failing
loudly at load is the safer contract. The core-side test pins the SDK constant
to `DagSerialization.SERIALIZER_VERSION`, keeping the two in lockstep.
##########
task-sdk/src/airflow/sdk/bases/operatorlink.py:
##########
@@ -55,12 +55,34 @@ def xcom_key(self) -> str:
"""
return f"_link_{self.__class__.__name__}"
- @abstractmethod
+ @property
+ def static_url(self) -> str | None:
+ """
+ Constant URL for this link, when it does not depend on the task run.
+
+ Links that override this property don't need an XCom entry: the URL is
+ carried through DAG serialization and rendered directly by the API
+ server, even for task instances that never pushed it via
``get_link()``.
+
+ Defaults to ``None``, meaning the link is resolved dynamically through
+ :meth:`get_link` and stored in XComs as before. Set it (instead of
+ overriding :meth:`get_link`) for links whose URL is always the same.
+ """
+ return None
+
def get_link(self, operator: BaseOperator, *, ti_key: TaskInstanceKey) ->
str:
"""
Link to external system.
+ Subclasses whose URL does not depend on the task run may override
+ :attr:`static_url` instead of this method and skip the XCom round-trip.
+
:param operator: The Airflow operator object this link is associated
to.
:param ti_key: TaskInstance ID to return link for.
:return: link to external system
"""
+ if self.static_url is not None:
+ return self.static_url
+ raise NotImplementedError(
Review Comment:
Agreed — learning about a broken link class at finalize, after the task ran,
is the wrong time. Fixed in `c54c467`: a concrete subclass that overrides
neither `get_link` nor `static_url` now fails with `TypeError` at class
definition time (at plugin import, earlier than any instantiation).
Two details worth flagging:
- Restoring `@abstractmethod` would have broken the static-only shape this
PR introduces (such links deliberately have no `get_link`), so instead the
guard requires *one of the two* members. `name` remains the only abstract
method.
- Intermediate bases that stay abstract are exempt (their concrete children
pick a link source). ABCMeta computes `__abstractmethods__` only after
`__init_subclass__` runs, so abstractness is re-derived from the MRO inside the
hook.
New tests in `task-sdk/tests/task_sdk/bases/test_operatorlink.py` cover the
guard, both accepted shapes, the through-intermediate inheritance, and the
exempt-abstract path.
--
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]