Skip to content

Commit

Permalink
Added the fix to add missing project length validation.
Browse files Browse the repository at this point in the history
 Addressing the issue - #4626
  • Loading branch information
lokeshrangineni committed Oct 14, 2024
1 parent 8e0c1b5 commit 85f8895
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sdk/python/feast/repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class RepoConfig(FeastBaseModel):
"""Repo config. Typically loaded from `feature_store.yaml`"""

project: StrictStr
""" str: Feast project id. This can be any alphanumeric string up to 16 characters.
""" 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 '_'.
You can have multiple independent feature repositories deployed to the same cloud
provider account, as long as they have different project ids.
provider account, as long as they have different project identifier.
"""

provider: StrictStr = "local"
Expand Down
8 changes: 6 additions & 2 deletions sdk/python/feast/repo_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def apply_total(repo_config: RepoConfig, repo_path: Path, skip_source_validation
store, registry = _get_store_and_registry(repo_config)
if not is_valid_name(project.name):
print(
f"{project.name} is not valid. Project name should only have "
f"{project.name} is not valid. Project name should not be more than 16 characters, should only have "
f"alphanumerical values and underscores but not start with an underscore."
)
sys.exit(1)
Expand Down Expand Up @@ -503,7 +503,11 @@ def init_repo(repo_name: str, template: str):

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


def generate_project_name() -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from sdk.python.feast.repo_operations import is_valid_name


def test_is_valid_name():
test_cases = [
# Valid project name cases
("valid_name1", True),
("username_1234", True),
("valid123", True),
("1234567890123456", True),
("invalid_name_", True),

# Invalid project name cases
("_invalidName", False),
("invalid-Name", False),
("too_long_name_123", False),
("invalid name", False),
("invalid@name", False),
("invalid$name", False),
("__", False),
("12345678901234567", False),
]

for name, expected in test_cases:
assert is_valid_name(name) == expected, f"Failed for project invalid name: {name}"

0 comments on commit 85f8895

Please sign in to comment.