Skip to content

Commit

Permalink
Rename Connection.to_json_dict to Connection.to_dict (#35894)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7594b7a)
  • Loading branch information
Taragolis authored and ephraimbuddy committed Dec 5, 2023
1 parent 7e9b6a4 commit 90f10b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions airflow/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion airflow/serialization/serialized_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 90f10b1

Please sign in to comment.