dondaum commented on PR #39299: URL: https://github.com/apache/airflow/pull/39299#issuecomment-2089195859
> > Fixed but still raise a warning > > [tests/serialization/test_pydantic_models.py:162](https://github.com/apache/airflow/blob/15eedd080428314cf6e27443f91624459d17a77d/tests/serialization/test_pydantic_models.py#L162) > > [tests/serialization/test_pydantic_models.py:163](https://github.com/apache/airflow/blob/15eedd080428314cf6e27443f91624459d17a77d/tests/serialization/test_pydantic_models.py#L163) > > Could you provide what kind of error you tried to fix? Both raised the following warnings ``` {"category": "sqlalchemy.exc.RemovedIn20Warning", "message": "\"DagScheduleDatasetReference\" object is being merged into a Session along the backref cascade path for relationship \"DatasetModel.consuming_dags\"; in SQLAlchemy 2.0, this reverse cascade will not take place. Set cascade_backrefs to False in either the relationship() or backref() function for the 2.0 behavior; or to set globally for the whole Session, set the future=True flag (Background on this error at: https://sqlalche.me/e/14/s9r1) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)", "filename": "tests/serialization/test_pydantic_models.py", "lineno": 162, "when": "runtest", "node_id": "tests/serialization/test_pydantic_models.py::test_serializing_pydantic_dataset_event", "group": "tests", "count": 1} {"category": "sqlalchemy.exc.RemovedIn20Warning", "message": "\"TaskOutletDatasetReference\" object is being merged into a Session along the backref cascade path for relationship \"DatasetModel.producing_tasks ``` We can fix it by first intializing the object, then adding it into the Session and then setting the dataset which is where the backref is happening. ```Python @pytest.mark.skipif(not _ENABLE_AIP_44, reason="AIP-44 is disabled") def test_serializing_pydantic_dataset_event(session, create_task_instance, create_dummy_dag): ... dag_ds_ref = DagScheduleDatasetReference(dag_id=dag.dag_id) session.add(dag_ds_ref) dag_ds_ref.dataset = ds1 task_ds_ref = TaskOutletDatasetReference(task_id=task1.task_id, dag_id=dag.dag_id) session.add(task_ds_ref) task_ds_ref.dataset = ds1 ``` Yet IMO the code would looks less readable than intializing the whole object first and add it into the Session. ```Python @pytest.mark.skipif(not _ENABLE_AIP_44, reason="AIP-44 is disabled") def test_serializing_pydantic_dataset_event(session, create_task_instance, create_dummy_dag): ... dag_ds_ref = DagScheduleDatasetReference(dag_id=dag.dag_id, dataset=ds1) task_ds_ref = TaskOutletDatasetReference(task_id=task1.task_id, dag_id=dag.dag_id, dataset=ds1) session.add_all([dag_ds_ref, task_ds_ref]) ``` -- 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]
