Skip to content

Commit

Permalink
Validate project name at apply (#1766)
Browse files Browse the repository at this point in the history
Signed-off-by: ted chang <htchang@us.ibm.com>
  • Loading branch information
tedhtchang authored Aug 17, 2021
1 parent 74c7bed commit c0fe653
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sdk/python/feast/repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
from typing import Any

import yaml
from pydantic import BaseModel, StrictInt, StrictStr, ValidationError, root_validator
from pydantic import (
BaseModel,
StrictInt,
StrictStr,
ValidationError,
root_validator,
validator,
)
from pydantic.error_wrappers import ErrorWrapper
from pydantic.typing import Dict, Optional, Union

Expand Down Expand Up @@ -180,6 +187,17 @@ def _validate_offline_store_config(cls, values):

return values

@validator("project")
def _validate_project_name(cls, v):
from feast.repo_operations import is_valid_name

if not is_valid_name(v):
raise ValueError(
f"Project name, {v}, should only have "
f"alphanumerical values and underscores but not start with an underscore."
)
return v


class FeastConfigError(Exception):
def __init__(self, error_message, config_path):
Expand Down
24 changes: 24 additions & 0 deletions sdk/python/tests/integration/scaffolding/test_repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,27 @@ def test_no_project():
"project\n"
" field required (type=value_error.missing)",
)


def test_invalid_project_name():
_test_config(
dedent(
"""
project: foo-1
registry: "registry.db"
provider: local
"""
),
expect_error="alphanumerical values ",
)

_test_config(
dedent(
"""
project: _foo
registry: "registry.db"
provider: local
"""
),
expect_error="alphanumerical values ",
)

0 comments on commit c0fe653

Please sign in to comment.