Skip to content

Commit

Permalink
Adding deprecation message for db storage type as file in config (dax…
Browse files Browse the repository at this point in the history
…a-ai#559)

* Adding deprecation message for db storage type as file in config

* Used Enum values in message
  • Loading branch information
dristysrivastava authored Sep 20, 2024
1 parent 4024d3d commit 8d8b27b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pebblo/app/config/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ def validate(self):
if not os.path.exists(expand_path(str(default_location))):
os.makedirs(expand_path(str(default_location)), exist_ok=True)

@staticmethod
def validate_input(input_dict):
deprecate_error = f"DeprecationWarning: '{StorageTypes.FILE.value}' in storage type is deprecated, use '{StorageTypes.DATABASE.value}' instead"

valid_storage_type = [storage_type.value for storage_type in StorageTypes]
input_storage_type = input_dict.get("storage", {}).get("type")
if input_storage_type not in valid_storage_type:
raise Exception(
f"Either '{StorageTypes.FILE.value}' or '{StorageTypes.DATABASE.value}' should be there in storage type"
)

if StorageTypes.FILE.value in input_storage_type:
print(deprecate_error)
return input_dict


def expand_path(file_path: str) -> str:
# Expand user (~) and environment variables
Expand Down Expand Up @@ -177,6 +192,7 @@ def validate_input(input_dict):
"""This function is used to validate input of config file"""
validators = {
"reports": ReportsConfig,
"storage": StorageConfig,
}

validation_errors = []
Expand Down
1 change: 0 additions & 1 deletion pebblo/app/enums/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class StorageTypes(Enum):

class DBStorageTypes(Enum):
SQLITE = "sqlite"
MONGODB = "mongodb"


class ClassificationMode(Enum):
Expand Down
40 changes: 40 additions & 0 deletions tests/app/config/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
DaemonConfig,
LoggingConfig,
ReportsConfig,
StorageConfig,
validate_config,
)

Expand Down Expand Up @@ -169,6 +170,45 @@ def test_classifier_config_validate():
]


def test_storage_config_validate():
# Test with storage type `file` correct value
storage = {"type": "file"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == []

# Test with storage type `db` correct value
storage = {"type": "db", "db": "sqlite", "name": "pebblo_db"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == []

# Test with wrong storage type
storage = {"type": "xyz"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == [
"Error: Unsupported storage type 'xyz' specified in the configuration.Valid values are ['file', 'db']"
]

# Test with storage type as `db` wrong `db` value
storage = {"type": "db", "db": "db123", "name": "pebblo_db"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == [
"Error: Unsupported db type 'db123' specified in the configuration.Valid values are ['sqlite']"
]

# Test with storage type as `db` without `db` and `name`
storage = {"type": "db"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == [
"Error: Unsupported db type 'None' specified in the configuration.Valid values are ['sqlite']",
"Error: Unsupported db name 'None specified in the configurationString values are allowed only",
]


def test_validate_config(setup_and_teardown):
# Test with valid configuration
config = {
Expand Down

0 comments on commit 8d8b27b

Please sign in to comment.