Skip to content

Conversation

@ashb
Copy link
Member

@ashb ashb commented Feb 24, 2022

In 2.2 we "deprecated" passing an execution date to XCom.get methods, but there was no other option for operator links.

Now in 2.3 as part of Dynamic Task Mapping (AIP-42) we will need to add map_index to the XCom row to support the "reduce" part of the API.

In order to support that cleanly we need to change the interface for BaseOperatorLink to take an identifier (as dttm/execution_date + task is no longer unique)

This PR adds support for passing a ti_key to operator link callbacks if the signature supports it.

Todo:

  • Add note in UPDATING.md about the change.

@ashb ashb force-pushed the change-operatorlink-interface branch from 3bde371 to 4d2fd52 Compare February 25, 2022 15:55
Comment on lines +259 to +265
Copy link
Member Author

@ashb ashb Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uranusjr Do you think this is enough of a check, or should we force ti_key to be accepted only as a keyword argument?

Is it worth doing a __init_subclass__ check on BaseOperatorLink to check the signature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be good enough. Can’t think of all the future possibilities but this should be strict enough, if we always call get_link with keyword ti_key (we already do here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was broadly a duplicate of test_extra_serialized_field_and_operator_links -- so I made that parameterized instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New base class for as almost all of the links in Google provider follow this simple pattern.

@ashb ashb changed the title WIP: Change BaseOperatorLink interface to take a ti_key, not a datetime Change BaseOperatorLink interface to take a ti_key, not a datetime Feb 25, 2022
@ashb ashb marked this pull request as ready for review February 25, 2022 22:36
@ashb ashb requested review from dstandish and uranusjr and removed request for XD-DENG, bbovenzi, ryanahamilton and turbaszek February 25, 2022 22:36
Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All minor thoughts, generally looks good to me.

Comment on lines +259 to +265
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be good enough. Can’t think of all the future possibilities but this should be strict enough, if we always call get_link with keyword ti_key (we already do here).

Comment on lines 51 to 56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing the backward compatibility topic, this particular class may not need to implement the compatibility signature? If we don’t support getting the link through the Python API, this one can only be called by Airflow core and only with the new API. (The same does not apply for operators in providers, of course.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You make a good point. I was just doing all of them without paying that much attention where the operator was defined.

Copy link
Member Author

@ashb ashb Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh,

airflow/operators/trigger_dagrun.py:51: error: Signature of "get_link"
incompatible with supertype "BaseOperatorLink"  [override]
        def get_link(
        ^

Maybe the override doesn't actually hurts us here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to remove the overload, if that doesn't cause typing problems for the providers I'll leave it just with the new signature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just implementing the new signature should work fine. We could also implement the compatibility signature and ignore the compatibility arguments (with a note explaining this is fine).

@ashb ashb force-pushed the change-operatorlink-interface branch from a43f108 to 1eed46e Compare February 28, 2022 18:41
@uranusjr
Copy link
Member

Would it be a good idea if serialize_value also take ti_key instead? cc @dstandish

@ashb
Copy link
Member Author

ashb commented Mar 1, 2022

Would it be a good idea if serialize_value also take ti_key instead? cc @dstandish

I agree, I've done it as part of 2edebe2 in #21710 (for no real reason, other than we are making larger changes there) -- this PR was concerned with just the changes needed for OperatorLink interface.

@ashb ashb force-pushed the change-operatorlink-interface branch from 8dae837 to 6fc80d5 Compare March 1, 2022 10:14
@github-actions
Copy link

github-actions bot commented Mar 1, 2022

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Mar 1, 2022
@ashb ashb merged commit 08575dd into apache:main Mar 1, 2022
@ashb ashb deleted the change-operatorlink-interface branch March 1, 2022 14:30
@ephraimbuddy ephraimbuddy added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Apr 8, 2022
@jedcunningham jedcunningham added this to the Airflow 2.3.0 milestone Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-39 Timetables area:dynamic-task-mapping AIP-42 changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) full tests needed We need to run full set of tests for this PR to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants