From b152835cbe301ae684aa49dbf0b11ab83fcfeec4 Mon Sep 17 00:00:00 2001 From: Andrey Anshin Date: Mon, 27 Nov 2023 19:54:16 +0400 Subject: [PATCH] Rename `Connection.to_json_dict` to `Connection.to_dict` --- airflow/models/connection.py | 11 ++++------- airflow/serialization/serialized_objects.py | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/airflow/models/connection.py b/airflow/models/connection.py index 1e835b4673dab..4e8e3c7aaf282 100644 --- a/airflow/models/connection.py +++ b/airflow/models/connection.py @@ -478,10 +478,7 @@ def get_connection_from_secrets(cls, conn_id: str) -> Connection: raise AirflowNotFoundException(f"The conn_id `{conn_id}` isn't defined") - def to_dict(self) -> dict[str, Any]: - return {"conn_id": self.conn_id, "description": self.description, "uri": self.get_uri()} - - def to_json_dict(self, *, prune_empty: bool = False, validate: bool = True) -> dict[str, Any]: + def to_dict(self, *, prune_empty: bool = False, validate: bool = True) -> dict[str, Any]: """ Convert Connection to json-serializable dictionary. @@ -528,6 +525,6 @@ def from_json(cls, value, conn_id=None) -> Connection: def as_json(self) -> str: """Convert Connection to JSON-string object.""" - conn = self.to_json_dict(prune_empty=True, validate=False) - conn.pop("conn_id", None) - return json.dumps(conn) + conn_repr = self.to_dict(prune_empty=True, validate=False) + conn_repr.pop("conn_id", None) + return json.dumps(conn_repr) diff --git a/airflow/serialization/serialized_objects.py b/airflow/serialization/serialized_objects.py index c40d4703eea8b..6f0e88cae2de2 100644 --- a/airflow/serialization/serialized_objects.py +++ b/airflow/serialization/serialized_objects.py @@ -498,7 +498,7 @@ def serialize( type_=DAT.SIMPLE_TASK_INSTANCE, ) elif isinstance(var, Connection): - return cls._encode(var.to_json_dict(validate=True), type_=DAT.CONNECTION) + return cls._encode(var.to_dict(validate=True), type_=DAT.CONNECTION) elif use_pydantic_models and _ENABLE_AIP_44: def _pydantic_model_dump(model_cls: type[BaseModel], var: Any) -> dict[str, Any]: