airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Optional support for static Extra Links without XCom dependency

Open zach-overflow opened this issue 1 year ago • 9 comments

Description

This feature request entails the addition of an opt-in feature for extra links which are not stored as an XCom, for static URLs and reduced metaDB bloat.

Use case/motivation

As far as I'm aware, extra links are only supported via XComs. This makes sense for dynamic, task-instance specific / DAG-run specific URLs (e.g. a link to an external Spark job); however, XComs are not an ideal mechanism for static URLs which are only specific to the given operator (rather than the task instance). For example, a very common use case for the Extra Links feature is to point to a static, operator-specific documentation page. Yet, storing that URL in an XCom for each task instance is clearly not ideal in that circumstance, and only adds bloat to the metaDB.

Related issues

Only very tangentially related: https://github.com/apache/airflow/issues/54527

Are you willing to submit a PR?

  • [x] Yes I am willing to submit a PR!

Caveat: I am willing to help with the backend implementation, but I have no understanding or experience regarding react / frontend development.

Code of Conduct

zach-overflow avatar Sep 09 '25 18:09 zach-overflow

What is the metaDB? I searched the airflow repo and couldn't find reference to this. Also why aren't XCOM's static, we set variables and retrieve them from downstream tasks (they aren't urls, but they don't change...)?

pierceroberts avatar Oct 27 '25 19:10 pierceroberts

I'd like to second this request. Right now buttons only show up once a task succeeds. They do not show up while a task is running nor when a task has failed because no xcoms were returned. This really reduces the utility of the buttons compared to AF3

NilsJPWerner avatar Oct 28 '25 21:10 NilsJPWerner

What is the metaDB? I searched the airflow repo and couldn't find reference to this.

Sorry, I believe the official term is the "Metadata Database", but that's a mouthful so I just shorthand it as "metaDB"; however, that isn't an official Airflow term.

Also why aren't XCOM's static, we set variables and retrieve them from downstream tasks (they aren't urls, but they don't change...)?

My concern is not whether XComs are static or not, but rather that using XComs to surface static extra links (i.e. specific extra links which do not change per task instance) is heavy-handed and adds unnecessary load to the database. I mentioned a few examples in this issue description where you might want to refer to the same static URL for a particular operator's extra links.

zach-overflow avatar Oct 29 '25 13:10 zach-overflow

Okay thanks for the info @zach-overflow ! So for this issue, is the idea to add an optional flag to extra_link.py? If so, I'd like to give it a go.

pierceroberts avatar Nov 08 '25 18:11 pierceroberts

@zach-overflow, which version of Airflow are you using?

jroachgolf84 avatar May 19 '26 16:05 jroachgolf84

@jroachgolf84 3.2.1

zach-overflow avatar Jun 09 '26 20:06 zach-overflow

Hi! I implemented this feature and submitted a PR here: https://github.com/apache/airflow/pull/70343

I added a static_url property to BaseOperatorLink that returns None by default. When overridden, get_link() returns it directly — no XCom push needed. All existing subclasses are fully unaffected.

Happy to incorporate any feedback!

iRAFEEK avatar Jul 23 '26 23:07 iRAFEEK

Hi! I'd like to work on this.

I've gone through the discussion and PR #70343 (closed by @kaxil). The key lesson: a Task-SDK-only static_url override is not sufficient — the API server deserializes operator links as XComOperatorLink, so a static URL must survive serialization and be resolvable there without an XCom lookup, otherwise the links render empty in the UI.

Plan:

  • Add an optional static_url override on BaseOperatorLink (defaults to None, get_link() falls back to it)
  • Carry static URLs through the serialization path and make the API-server link resolution return them directly instead of querying XCom
  • Unit tests at the SDK, serialization, and API-server resolution layers, plus a docs note for defining extra links

I'll open a PR within 48h. If @iRAFEEK or anyone else is still actively working on this, happy to coordinate.

Abolfazlrwm avatar Nov 06 '26 18:11 Abolfazlrwm

Two implementation attempts have now landed on the same wall, so before anyone (myself included) spends another round on this, it would help a lot to settle the design direction.

Where the previous attempts ended:

  • #70343 (task-SDK-only static_url) was closed by @kaxil with the key lesson: the API server resolves operator links as XComOperatorLink reading from XCom, so anything that only lives on the Task-SDK side renders as an empty link in the UI. A static URL must be carried through the serialized DAG.
  • #76627 (full multi-layer change, incl. SERIALIZATION_VERSION 3 → 4 with a v3→v4 conversion) addressed that, but was withdrawn by its author this week — so the cross-layer questions it raised never got a committer ruling.

The questions I think need an answer before attempt #3:

  1. Serialization strategy. #76627 bumped DagSerialization.SERIALIZER_VERSION to 4, which means bundles written by core ≥ this version will be rejected by cores that only know ≤ 3 (Unsure how to deserialize version 4). Is that trade-off acceptable here, or is there a preference for an additive, non-bumping representation (e.g. encoding static links through the existing link entry shape) that keeps older cores loading new bundles?
  2. Link-class shape. Should BaseOperatorLink grow an optional static_url while keeping get_link overridable, with a guard that a concrete subclass must override at least one of them at class-definition time (avoids deferring the error to finalize(), after the task already ran — @guan404ming's point in #76627)?
  3. When do the buttons render? Today XCom-backed links only show after the task succeeds (which also breaks the use case @NilsJPWerner described — no buttons while running or failed). Static links resolvable from the serialized DAG alone could be returned for any task state. Is that the desired behavior?
  4. Skip the XCom push. For the metaDB-bloat motivation to actually materialize, task_runner.py must skip the XCom push for static links (the fix @aaron-y-chen prompted in #70343). I'd treat that as in-scope rather than follow-up.

If maintainers can confirm a direction on (1) — v4 bump vs non-bumping — I'm happy to take the implementation on (building on the lessons from both prior PRs, credit to @iRAFEEK and the #76627 author for the groundwork).

rmfrall avatar Nov 28 '26 15:11 rmfrall