Skip to content

Commit 3d3a2cd

Browse files
Added the fix to add missing project length validation.
Addressing the issue - #4626 Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com> Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com> Added the fix to add missing project length validation. Addressing the issue - #4626 Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com>
1 parent 8e0c1b5 commit 3d3a2cd

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

sdk/python/feast/repo_config.py

+2-2
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

+7-2
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,12 @@ 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 # the name is not greater than 16 characters
508+
and not name.startswith("_") # name does not start with an underscore
509+
and re.match(r"^[a-zA-Z0-9_]+$", name)
510+
is not None # Ensures it only contains alphanumeric and _
511+
)
507512

508513

509514
def generate_project_name() -> str:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
# Invalid project name cases
13+
("_invalidName", False),
14+
("invalid-Name", False),
15+
("too_long_name_123", False),
16+
("invalid name", False),
17+
("invalid@name", False),
18+
("invalid$name", False),
19+
("__", False),
20+
("12345678901234567", False),
21+
]
22+
23+
for name, expected in test_cases:
24+
assert (
25+
is_valid_name(name) == expected
26+
), f"Failed for project invalid name: {name}"

0 commit comments

Comments
 (0)