From 607055d55a3c60665998f1e7cdf9b9b4d3bdbefa Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 12:48:23 +0100 Subject: [PATCH] Raise an error if `Path._directions` is not set ... ... instead of failing inside `json.loads()` on `None` --- src/velofy/db/addresses_addresses.py | 3 +++ tests/db/test_addresses_addresses.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index 0ab22f1..682f111 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -270,6 +270,9 @@ class Path(meta.Base): Implementation detail: This property is cached as none of the underlying attributes (i.e., `._directions`) are to be changed. """ + if not self._directions: + raise RuntimeError("_directions is not set") + points = [utils.Location(*point) for point in json.loads(self._directions)] for point in points: point.relate_to(self.first_address.city.southwest) diff --git a/tests/db/test_addresses_addresses.py b/tests/db/test_addresses_addresses.py index e4fdb6d..9d9f91d 100644 --- a/tests/db/test_addresses_addresses.py +++ b/tests/db/test_addresses_addresses.py @@ -670,6 +670,13 @@ class TestSyncWithGoogleMaps: class TestProperties: """Test properties in `Path`.""" + def test_waypoints_no_directions(self, path): + """Test `Path.waypoints` property.""" + path._directions = None + + with pytest.raises(RuntimeError, match="not set"): + int(path.waypoints) + def test_waypoints_structure(self, path): """Test `Path.waypoints` property.""" result = path.waypoints