Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate project name upon feast.apply #1766

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ",
)