diff --git a/src/bentoml/_internal/cloud/deployment.py b/src/bentoml/_internal/cloud/deployment.py index ed65448348e..dd36f74ce29 100644 --- a/src/bentoml/_internal/cloud/deployment.py +++ b/src/bentoml/_internal/cloud/deployment.py @@ -442,11 +442,10 @@ def is_dev(self) -> bool: return self._schema.manifest is not None and self._schema.manifest.dev def to_dict(self) -> dict[str, t.Any]: - return { + result = { "name": self.name, "bento": self.get_bento(refetch=False), "cluster": self.cluster, - "endpoint_urls": self._urls if self._urls else None, "admin_console": self.admin_console, "created_at": self.created_at, "created_by": self.created_by, @@ -458,6 +457,13 @@ def to_dict(self) -> dict[str, t.Any]: "status": self.get_status(refetch=False).to_dict(), } + # Add "endpoint_urls" only if it's not None + if self._urls: + result["endpoint_urls"] = self._urls + + return result + + def to_yaml(self): return yaml.dump(self.to_dict(), sort_keys=False)