Skip to content

Conversation

@amoghrajesh
Copy link
Contributor

@amoghrajesh amoghrajesh commented Jan 31, 2025

related: #45739

#41363 is a feature that heavily relied on pydantic models of AIP 44 to do some serialisation magic.

Historically did this:

            if self.use_airflow_context:
                from airflow.serialization.serialized_objects import BaseSerialization

                context = get_current_context()
                with create_session() as session:
                    # FIXME: DetachedInstanceError
                    dag_run, task_instance = context["dag_run"], context["task_instance"]
                    session.add_all([dag_run, task_instance])
                    serializable_context: dict[Encoding, Any] = BaseSerialization.serialize(
                        context, use_pydantic_models=True
                    )
  • So it used a pydantic model to serialize the DAG.
  • And the mapping looked like so:
_type_to_class: dict[DAT | str, list] = {
    DAT.BASE_JOB: [JobPydantic, Job],
    DAT.TASK_INSTANCE: [TaskInstancePydantic, TaskInstance],
    DAT.DAG_RUN: [DagRunPydantic, DagRun],
    DAT.DAG_MODEL: [DagModelPydantic, DagModel],
    DAT.LOG_TEMPLATE: [LogTemplatePydantic, LogTemplate],
    DAT.DATA_SET: [DatasetPydantic, Dataset],
    DAT.TRIGGER: [TriggerPydantic, Trigger],
}
  • And this:
def serialize_operator(x: DAG) -> dict:
    from airflow.serialization.serialized_objects import SerializedDAG

    return SerializedDAG.serialize_dag(x)


def validate_operator(x: DAG | dict[str, Any], _info: ValidationInfo) -> Any:
    from airflow.serialization.serialized_objects import SerializedDAG

    if isinstance(x, DAG):
        return x
    return SerializedDAG.deserialize_dag(x)

Since now we do not have the pydantic models of AIP 44 AND the fact that this didnt make it to any release, now is a time to chop it off.

cc: @phi-friday


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@amoghrajesh amoghrajesh changed the title Removing feature: send context in venv operators Removing feature: send context in venv operators (using use_airflow_context) Jan 31, 2025
@ashb
Copy link
Member

ashb commented Jan 31, 2025

For context on why we are removing this:

  1. It never actually made it in to a release (it was tagged with 2.10.0 milestone but somehow got missed in that release)
  2. It relies on AIP-44 and the pydantic models it creates to work, and those have been removed in main/Airflow 3
  3. With the split out of the new standard provider it will be easier to add this back in quicker, but trying to support it now will delay Airflow 3 work as we have a long list of critical features related ti AIP-72/Task Execution interface, and unfortunately we have to cut something.

Sorry to revert this yet again :(

@amoghrajesh
Copy link
Contributor Author

@ephraimbuddy are we good to send this one in?

@potiuk
Copy link
Member

potiuk commented Jan 31, 2025

Makes sense. Thanks for the reasoning @ashb . Should we also add an issue for 3.1 to re-add it ?

@amoghrajesh amoghrajesh merged commit 3ff4f2d into apache:main Feb 3, 2025
62 checks passed
@amoghrajesh amoghrajesh deleted the nuke-use-airflow-context-AF3 branch February 3, 2025 06:11
@amoghrajesh
Copy link
Contributor Author

Makes sense. Thanks for the reasoning @ashb . Should we also add an issue for 3.1 to re-add it ?

Thanks @potiuk, created #46361 for tracking sake.

amoghrajesh added a commit to astronomer/airflow that referenced this pull request Feb 3, 2025
dabla pushed a commit to dabla/airflow that referenced this pull request Feb 3, 2025
ambika-garg pushed a commit to ambika-garg/airflow that referenced this pull request Feb 4, 2025
niklasr22 pushed a commit to niklasr22/airflow that referenced this pull request Feb 8, 2025
ambika-garg pushed a commit to ambika-garg/airflow that referenced this pull request Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants