Skip to content

Commit 85f8895

Browse files
Added the fix to add missing project length validation.
Addressing the issue - feast-dev#4626
1 parent 8e0c1b5 commit 85f8895

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎sdk/python/feast/repo_config.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ class RepoConfig(FeastBaseModel):
158158
"""Repo config. Typically loaded from `feature_store.yaml`"""
159159

160160
project: StrictStr
161-
""" str: Feast project id. This can be any alphanumeric string up to 16 characters.
161+
""" str: This acts as a unique project identifier. This can be any alphanumeric string up to 16 characters and can have '_' but can not start with '_'.
162162
You can have multiple independent feature repositories deployed to the same cloud
163-
provider account, as long as they have different project ids.
163+
provider account, as long as they have different project identifier.
164164
"""
165165

166166
provider: StrictStr = "local"

‎sdk/python/feast/repo_operations.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def apply_total(repo_config: RepoConfig, repo_path: Path, skip_source_validation
395395
store, registry = _get_store_and_registry(repo_config)
396396
if not is_valid_name(project.name):
397397
print(
398-
f"{project.name} is not valid. Project name should only have "
398+
f"{project.name} is not valid. Project name should not be more than 16 characters, should only have "
399399
f"alphanumerical values and underscores but not start with an underscore."
400400
)
401401
sys.exit(1)
@@ -503,7 +503,11 @@ def init_repo(repo_name: str, template: str):
503503

504504
def is_valid_name(name: str) -> bool:
505505
"""A name should be alphanumeric values and underscores but not start with an underscore"""
506-
return not name.startswith("_") and re.compile(r"\W+").search(name) is None
506+
return (
507+
len(name) <= 16 and # the name is not greater than 16 characters
508+
not name.startswith("_") and # name does not start with an underscore
509+
re.match(r"^[a-zA-Z0-9_]+$", name) is not None # Ensures it only contains alphanumeric and _
510+
)
507511

508512

509513
def generate_project_name() -> str:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from sdk.python.feast.repo_operations import is_valid_name
2+
3+
4+
def test_is_valid_name():
5+
test_cases = [
6+
# Valid project name cases
7+
("valid_name1", True),
8+
("username_1234", True),
9+
("valid123", True),
10+
("1234567890123456", True),
11+
("invalid_name_", True),
12+
13+
# Invalid project name cases
14+
("_invalidName", False),
15+
("invalid-Name", False),
16+
("too_long_name_123", False),
17+
("invalid name", False),
18+
("invalid@name", False),
19+
("invalid$name", False),
20+
("__", False),
21+
("12345678901234567", False),
22+
]
23+
24+
for name, expected in test_cases:
25+
assert is_valid_name(name) == expected, f"Failed for project invalid name: {name}"

0 commit comments

Comments
 (0)