From ada436c3457bc6f80febdb0056f60ffaa4d9de42 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Wed, 24 Jan 2024 17:38:06 +0000 Subject: [PATCH] :bug: Allow SoftwarePackageCategory to be correctly serialised and deserialised as a string --- data_safe_haven/config/config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data_safe_haven/config/config.py b/data_safe_haven/config/config.py index ea025747a5..91460e8423 100644 --- a/data_safe_haven/config/config.py +++ b/data_safe_haven/config/config.py @@ -8,6 +8,7 @@ from azure.keyvault.keys import KeyVaultKey from pydantic import ( BaseModel, + ConfigDict, Field, FieldSerializationInfo, ValidationError, @@ -149,6 +150,7 @@ def update( class ConfigSectionSRE(BaseModel, validate_assignment=True): + model_config = ConfigDict(use_enum_values=True) databases: list[DatabaseSystem] = Field(..., default_factory=list[DatabaseSystem]) data_provider_ip_addresses: list[IpAddress] = Field( ..., default_factory=list[IpAddress] @@ -176,9 +178,11 @@ def all_databases_must_be_unique( @field_serializer("software_packages") def software_packages_serializer( self, - packages: SoftwarePackageCategory, + packages: SoftwarePackageCategory | str, info: FieldSerializationInfo, # noqa: ARG002 ) -> str: + if isinstance(packages, str): + packages = SoftwarePackageCategory(packages) return packages.value def update(