Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix host set_comment with empty comment #283

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions mreg_cli/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,7 +2493,7 @@ class Host(FrozenModelWithTimestamps, WithTTL, WithHistory, APIMixin):
bacnetid: int | None = None
contact: str
ttl: int | None = None
comment: str | None = None
comment: str

# Note, we do not use WithZone here as this is optional and we resolve it differently.
zone: int | None = None
Expand All @@ -2506,12 +2506,6 @@ def validate_name(cls, value: str) -> HostT:
"""Validate the hostname."""
return HostT(hostname=value)

@field_validator("comment", mode="before")
@classmethod
def empty_string_to_none(cls, v: str) -> str | None:
"""Convert empty strings to None."""
return v or None

@field_validator("bacnetid", mode="before")
@classmethod
def convert_bacnetid(cls, v: dict[str, int] | None) -> int | None:
Expand Down Expand Up @@ -3027,7 +3021,7 @@ def output(self, names: bool = False, traverse_hostgroups: bool = False):
output_manager.add_line(f"{'Name:':<{padding}}{self.name}")
output_manager.add_line(f"{'Contact:':<{padding}}{self.contact}")

if self.comment is not None and self.comment != "":
if self.comment:
output_manager.add_line(f"{'Comment:':<{padding}}{self.comment}")

self.output_ipaddresses(padding=padding, names=names)
Expand Down Expand Up @@ -3186,7 +3180,7 @@ def _format(name: str, contact: str, comment: str) -> None:

_format("Name", "Contact", "Comment")
for i in self.results:
_format(str(i.name), i.contact, i.comment or "")
_format(str(i.name), i.contact, i.comment)


class HostGroup(FrozenModelWithTimestamps, WithName, WithHistory, APIMixin):
Expand Down
Loading