From 3c6198a749d86040c68005ba41bbd71a28a4ffe4 Mon Sep 17 00:00:00 2001 From: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com> Date: Mon, 15 Dec 2025 09:26:43 -0800 Subject: [PATCH] fix: handle None value for environment field in EnvironmentTemplate Add type check in _validate_has_script_or_variables to raise a proper ValidationError when environment is None instead of AttributeError. Signed-off-by: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com> --- src/openjd/model/v2023_09/_model.py | 2 ++ test/openjd/model/v2023_09/test_environment_template.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/openjd/model/v2023_09/_model.py b/src/openjd/model/v2023_09/_model.py index b0a88371..890b7ed3 100644 --- a/src/openjd/model/v2023_09/_model.py +++ b/src/openjd/model/v2023_09/_model.py @@ -1055,6 +1055,8 @@ class Environment(OpenJDModel_v2023_09): @model_validator(mode="before") @classmethod def _validate_has_script_or_variables(cls, values: dict[str, Any]) -> dict[str, Any]: + if not isinstance(values, dict): + raise ValueError("Environment must be a mapping.") if values.get("script") is None and values.get("variables") is None: raise ValueError("Environment must have either a script or variables.") return values diff --git a/test/openjd/model/v2023_09/test_environment_template.py b/test/openjd/model/v2023_09/test_environment_template.py index edef1b06..864e1345 100644 --- a/test/openjd/model/v2023_09/test_environment_template.py +++ b/test/openjd/model/v2023_09/test_environment_template.py @@ -102,6 +102,14 @@ def test_parse_success(self, data: dict[str, Any]) -> None: 1, id="missing spec ver", ), + pytest.param( + { + "specificationVersion": "environment-2023-09", + "environment": None, + }, + 1, + id="environment is None", + ), # pytest.param( {