From 4ffa1a65c694cc20863c8e307a682c5018996e23 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 18 Dec 2021 14:04:47 +0100 Subject: [PATCH] Fix device created empty string (#29) --- src/tailscale/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tailscale/models.py b/src/tailscale/models.py index ddc5dd2..ae4aed9 100644 --- a/src/tailscale/models.py +++ b/src/tailscale/models.py @@ -54,6 +54,21 @@ class Device(BaseModel): advertised_routes: List[str] = Field(alias="advertisedRoutes", default_factory=list) client_connectivity: ClientConnectivity = Field(alias="clientConnectivity") + @validator("created", pre=True) + @classmethod + def empty_as_none(cls, data: str | None) -> str | None: # noqa: F841 + """Convert an emtpty string to None. + + Args: + data: String to convert. + + Returns: + String or none if string is empty. + """ + if not data: + return None + return data + class Devices(BaseModel): """Object holding Tailscale device information."""