From a44d68f1ee689d55dccfe67440e4ee1aea806f2d Mon Sep 17 00:00:00 2001 From: Antoine Jeannot Date: Fri, 19 Jan 2024 12:06:32 +0100 Subject: [PATCH] storage driver settings: ignore extra --- modelkit/assets/drivers/azure.py | 2 +- modelkit/assets/drivers/gcs.py | 2 +- modelkit/assets/drivers/local.py | 2 +- modelkit/assets/drivers/s3.py | 2 +- tests/test_settings.py | 26 ++++++++++++++++++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modelkit/assets/drivers/azure.py b/modelkit/assets/drivers/azure.py index 3e293aaa..e0df5b1a 100644 --- a/modelkit/assets/drivers/azure.py +++ b/modelkit/assets/drivers/azure.py @@ -22,7 +22,7 @@ class AzureStorageDriverSettings(StorageDriverSettings): "connection_string", "AZURE_STORAGE_CONNECTION_STRING" ), ) - model_config = pydantic.ConfigDict(extra="forbid") + model_config = pydantic.ConfigDict(extra="ignore") class AzureStorageDriver(StorageDriver): diff --git a/modelkit/assets/drivers/gcs.py b/modelkit/assets/drivers/gcs.py index 4d93b656..f94b5ebf 100644 --- a/modelkit/assets/drivers/gcs.py +++ b/modelkit/assets/drivers/gcs.py @@ -24,7 +24,7 @@ class GCSStorageDriverSettings(StorageDriverSettings): "service_account_path", "GOOGLE_APPLICATION_CREDENTIALS" ), ) - model_config = pydantic.ConfigDict(extra="forbid") + model_config = pydantic.ConfigDict(extra="ignore") class GCSStorageDriver(StorageDriver): diff --git a/modelkit/assets/drivers/local.py b/modelkit/assets/drivers/local.py index 37c39e16..c6d047bc 100644 --- a/modelkit/assets/drivers/local.py +++ b/modelkit/assets/drivers/local.py @@ -13,7 +13,7 @@ class LocalStorageDriverSettings(StorageDriverSettings): - model_config = pydantic.ConfigDict(extra="forbid") + model_config = pydantic.ConfigDict(extra="ignore") class LocalStorageDriver(StorageDriver): diff --git a/modelkit/assets/drivers/s3.py b/modelkit/assets/drivers/s3.py index 10f051ca..17f21931 100644 --- a/modelkit/assets/drivers/s3.py +++ b/modelkit/assets/drivers/s3.py @@ -47,7 +47,7 @@ class S3StorageDriverSettings(StorageDriverSettings): aws_kms_key_id: Optional[str] = pydantic.Field( None, validation_alias=pydantic.AliasChoices("aws_kms_key_id", "AWS_KMS_KEY_ID") ) - model_config = pydantic.ConfigDict(extra="forbid") + model_config = pydantic.ConfigDict(extra="ignore") class S3StorageDriver(StorageDriver): diff --git a/tests/test_settings.py b/tests/test_settings.py index 56935410..b6944364 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,5 +1,11 @@ import pydantic +import pytest +from modelkit.assets.drivers.abc import StorageDriverSettings +from modelkit.assets.drivers.azure import AzureStorageDriverSettings +from modelkit.assets.drivers.gcs import GCSStorageDriverSettings +from modelkit.assets.drivers.local import LocalStorageDriverSettings +from modelkit.assets.drivers.s3 import S3StorageDriverSettings from modelkit.core.settings import ModelkitSettings @@ -22,3 +28,23 @@ class ServingSettings(ModelkitSettings): # because both `enable` and `SERVING_ENABLE` are set and passed to the # constructor. assert ServingSettings(enable=False).enable is False + + +@pytest.mark.parametrize( + "Settings", + [ + StorageDriverSettings, + GCSStorageDriverSettings, + AzureStorageDriverSettings, + S3StorageDriverSettings, + LocalStorageDriverSettings, + ], +) +def test_storage_driver_settings(Settings, monkeypatch): + monkeypatch.setenv("MODELKIT_STORAGE_BUCKET", "foo") + assert Settings().bucket == "foo" + assert Settings(bucket="bar").bucket == "bar" + monkeypatch.delenv("MODELKIT_STORAGE_BUCKET") + assert Settings(bucket="bar").bucket == "bar" + with pytest.raises(pydantic.ValidationError): + _ = Settings()