diff --git a/data_safe_haven/functions/typer_validators.py b/data_safe_haven/functions/typer_validators.py index df72cd149c..91434740d9 100644 --- a/data_safe_haven/functions/typer_validators.py +++ b/data_safe_haven/functions/typer_validators.py @@ -13,7 +13,13 @@ def typer_validator_factory(validator: Callable[[Any], Any]) -> Callable[[Any], Any]: + """Factory to create validation functions for Typer from Pydantic validators""" def typer_validator(x: Any) -> Any: + # Return unused optional arguments + if x is None: + return x + + # Validate input, catching ValueError to raise Typer Exception try: validator(x) return x diff --git a/tests_/functions/test_typer_validators.py b/tests_/functions/test_typer_validators.py index 0c9c02ff90..72ae8b3f53 100644 --- a/tests_/functions/test_typer_validators.py +++ b/tests_/functions/test_typer_validators.py @@ -26,3 +26,6 @@ def test_typer_validate_aad_guid_fail(self, guid): with pytest.raises(BadParameter) as exc: typer_validate_aad_guid(guid) assert "Expected GUID" in exc + + def test_typer_validate_aad_guid_nonae(self): + assert typer_validate_aad_guid(None) is None