Skip to content

Commit c0fe653

Browse files
authored
Validate project name at apply (#1766)
Signed-off-by: ted chang <htchang@us.ibm.com>
1 parent 74c7bed commit c0fe653

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎sdk/python/feast/repo_config.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
from typing import Any
33

44
import yaml
5-
from pydantic import BaseModel, StrictInt, StrictStr, ValidationError, root_validator
5+
from pydantic import (
6+
BaseModel,
7+
StrictInt,
8+
StrictStr,
9+
ValidationError,
10+
root_validator,
11+
validator,
12+
)
613
from pydantic.error_wrappers import ErrorWrapper
714
from pydantic.typing import Dict, Optional, Union
815

@@ -180,6 +187,17 @@ def _validate_offline_store_config(cls, values):
180187

181188
return values
182189

190+
@validator("project")
191+
def _validate_project_name(cls, v):
192+
from feast.repo_operations import is_valid_name
193+
194+
if not is_valid_name(v):
195+
raise ValueError(
196+
f"Project name, {v}, should only have "
197+
f"alphanumerical values and underscores but not start with an underscore."
198+
)
199+
return v
200+
183201

184202
class FeastConfigError(Exception):
185203
def __init__(self, error_message, config_path):

‎sdk/python/tests/integration/scaffolding/test_repo_config.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,27 @@ def test_no_project():
153153
"project\n"
154154
" field required (type=value_error.missing)",
155155
)
156+
157+
158+
def test_invalid_project_name():
159+
_test_config(
160+
dedent(
161+
"""
162+
project: foo-1
163+
registry: "registry.db"
164+
provider: local
165+
"""
166+
),
167+
expect_error="alphanumerical values ",
168+
)
169+
170+
_test_config(
171+
dedent(
172+
"""
173+
project: _foo
174+
registry: "registry.db"
175+
provider: local
176+
"""
177+
),
178+
expect_error="alphanumerical values ",
179+
)

0 commit comments

Comments
 (0)