Skip to content

Commit 18879af

Browse files
committed
Make sure the context exists before trying to access it
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent cd0cb83 commit 18879af

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/frequenz/quantities/experimental/marshmallow.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ def _serialize(
6969
assert self.parent is not None
7070

7171
# Determine the serialization format
72-
serialize_as_string = self.metadata.get(
73-
"serialize_as_string",
74-
self.parent.context.get("serialize_as_string_default", False),
72+
default = (
73+
False
74+
if self.parent.context is None
75+
else self.parent.context.get("serialize_as_string_default", False)
7576
)
77+
serialize_as_string = self.metadata.get("serialize_as_string", default)
7678

7779
if serialize_as_string:
7880
# Use the Quantity's native string representation (includes unit)

0 commit comments

Comments
 (0)