From 89ffee9ad5ecb5c95f1d71e515e7df8b5134c062 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 5 Jul 2024 14:07:39 -0500 Subject: [PATCH] Update ulid-transform to 0.10.1 (#121321) --- .../components/recorder/models/context.py | 29 ++++--------------- homeassistant/package_constraints.txt | 2 +- homeassistant/util/ulid.py | 4 +++ pyproject.toml | 2 +- requirements.txt | 2 +- tests/components/recorder/test_init.py | 2 -- tests/components/recorder/test_models.py | 26 ----------------- 7 files changed, 13 insertions(+), 54 deletions(-) diff --git a/homeassistant/components/recorder/models/context.py b/homeassistant/components/recorder/models/context.py index 0d81bab879a695..90791163f82424 100644 --- a/homeassistant/components/recorder/models/context.py +++ b/homeassistant/components/recorder/models/context.py @@ -7,33 +7,16 @@ import logging from uuid import UUID -from homeassistant.util.ulid import bytes_to_ulid, ulid_to_bytes +from homeassistant.util.ulid import ( # noqa: F401 + bytes_to_ulid, + bytes_to_ulid_or_none, + ulid_to_bytes, + ulid_to_bytes_or_none, +) _LOGGER = logging.getLogger(__name__) -def ulid_to_bytes_or_none(ulid: str | None) -> bytes | None: - """Convert an ulid to bytes.""" - if ulid is None: - return None - try: - return ulid_to_bytes(ulid) - except ValueError: - _LOGGER.exception("Error converting ulid %s to bytes", ulid) - return None - - -def bytes_to_ulid_or_none(_bytes: bytes | None) -> str | None: - """Convert bytes to a ulid.""" - if _bytes is None: - return None - try: - return bytes_to_ulid(_bytes) - except ValueError: - _LOGGER.exception("Error converting bytes %s to ulid", _bytes) - return None - - @lru_cache(maxsize=16) def uuid_hex_to_bytes_or_none(uuid_hex: str | None) -> bytes | None: """Convert a uuid hex to bytes.""" diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 8b2d210658e963..93a27480b7e1bb 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -56,7 +56,7 @@ PyYAML==6.0.1 requests==2.32.3 SQLAlchemy==2.0.31 typing-extensions>=4.12.2,<5.0 -ulid-transform==0.9.0 +ulid-transform==0.10.1 urllib3>=1.26.5,<2 voluptuous-openapi==0.0.4 voluptuous-serialize==2.6.0 diff --git a/homeassistant/util/ulid.py b/homeassistant/util/ulid.py index 65f1b8226c0239..f4895f9d96342b 100644 --- a/homeassistant/util/ulid.py +++ b/homeassistant/util/ulid.py @@ -4,10 +4,12 @@ from ulid_transform import ( bytes_to_ulid, + bytes_to_ulid_or_none, ulid_at_time, ulid_hex, ulid_now, ulid_to_bytes, + ulid_to_bytes_or_none, ) __all__ = [ @@ -17,6 +19,8 @@ "ulid_to_bytes", "bytes_to_ulid", "ulid_now", + "ulid_to_bytes_or_none", + "bytes_to_ulid_or_none", ] diff --git a/pyproject.toml b/pyproject.toml index ecfe7fad8aed41..5b41ca17a5775d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ dependencies = [ "requests==2.32.3", "SQLAlchemy==2.0.31", "typing-extensions>=4.12.2,<5.0", - "ulid-transform==0.9.0", + "ulid-transform==0.10.1", # Constrain urllib3 to ensure we deal with CVE-2020-26137 and CVE-2021-33503 # Temporary setting an upper bound, to prevent compat issues with urllib3>=2 # https://github.com/home-assistant/core/issues/97248 diff --git a/requirements.txt b/requirements.txt index 969ca2d86eeeec..d2bae8096cd252 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,7 +37,7 @@ PyYAML==6.0.1 requests==2.32.3 SQLAlchemy==2.0.31 typing-extensions>=4.12.2,<5.0 -ulid-transform==0.9.0 +ulid-transform==0.10.1 urllib3>=1.26.5,<2 voluptuous==0.15.2 voluptuous-serialize==2.6.0 diff --git a/tests/components/recorder/test_init.py b/tests/components/recorder/test_init.py index 0504fcc8f9190c..adfc451c7429f9 100644 --- a/tests/components/recorder/test_init.py +++ b/tests/components/recorder/test_init.py @@ -944,8 +944,6 @@ async def test_saving_event_invalid_context_ulid( ) } - assert "invalid" in caplog.text - assert len(events) == 1 assert json_loads(events["test_event"]) == event_data diff --git a/tests/components/recorder/test_models.py b/tests/components/recorder/test_models.py index d06c4a629d7ef6..975d67a8e99c0b 100644 --- a/tests/components/recorder/test_models.py +++ b/tests/components/recorder/test_models.py @@ -15,11 +15,9 @@ ) from homeassistant.components.recorder.models import ( LazyState, - bytes_to_ulid_or_none, process_datetime_to_timestamp, process_timestamp, process_timestamp_to_utc_isoformat, - ulid_to_bytes_or_none, ) from homeassistant.const import EVENT_STATE_CHANGED import homeassistant.core as ha @@ -428,27 +426,3 @@ async def test_process_datetime_to_timestamp_mirrors_utc_isoformat_behavior( process_datetime_to_timestamp(datetime_hst_timezone) == dt_util.parse_datetime("2016-07-09T21:00:00+00:00").timestamp() ) - - -def test_ulid_to_bytes_or_none(caplog: pytest.LogCaptureFixture) -> None: - """Test ulid_to_bytes_or_none.""" - - assert ( - ulid_to_bytes_or_none("01EYQZJXZ5Z1Z1Z1Z1Z1Z1Z1Z1") - == b"\x01w\xaf\xf9w\xe5\xf8~\x1f\x87\xe1\xf8~\x1f\x87\xe1" - ) - assert ulid_to_bytes_or_none("invalid") is None - assert "invalid" in caplog.text - assert ulid_to_bytes_or_none(None) is None - - -def test_bytes_to_ulid_or_none(caplog: pytest.LogCaptureFixture) -> None: - """Test bytes_to_ulid_or_none.""" - - assert ( - bytes_to_ulid_or_none(b"\x01w\xaf\xf9w\xe5\xf8~\x1f\x87\xe1\xf8~\x1f\x87\xe1") - == "01EYQZJXZ5Z1Z1Z1Z1Z1Z1Z1Z1" - ) - assert bytes_to_ulid_or_none(b"invalid") is None - assert "invalid" in caplog.text - assert bytes_to_ulid_or_none(None) is None