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

feat: Force absolute paths in file based registries #4774

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions sdk/python/feast/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ def __init__(self, registry_type: str):
)


class FeastFileRegistryPathNotAbsoluteError(FeastError):
def __init__(self, path: str):
super().__init__(
f"File registry path was set to {path}, which is a relative path. "
"Please, specify the absolute path of the registry file in the feature_store.yaml"
)


class FeastModuleImportError(FeastError):
def __init__(self, module_name: str, class_name: str):
super().__init__(
Expand Down
10 changes: 10 additions & 0 deletions sdk/python/feast/repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from feast.errors import (
FeastFeatureServerTypeInvalidError,
FeastFileRegistryPathNotAbsoluteError,
FeastInvalidAuthConfigClass,
FeastOfflineStoreInvalidName,
FeastOnlineStoreInvalidName,
Expand Down Expand Up @@ -166,6 +167,15 @@ def validate_path(cls, path: str, values: ValidationInfo) -> str:
"explicitely to `path`."
)
return path.replace("postgresql://", "postgresql+psycopg://")

if values.data.get("registry_type") == "file":
is_local_file_registry = not (
path.startswith("s3://") or path.startswith("gs://")
)
is_relative_path = not os.path.isabs(path)
if is_local_file_registry and is_relative_path:
raise FeastFileRegistryPathNotAbsoluteError(str(path))

return path


Expand Down
19 changes: 18 additions & 1 deletion sdk/python/feast/repo_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,28 @@ def init_repo(repo_name: str, template: str):
os.remove(bootstrap_path)

# Template the feature_store.yaml file
feature_store_yaml_path = repo_path / "feature_repo" / "feature_store.yaml"
feature_repo_path = repo_path / "feature_repo"
feature_store_yaml_path = feature_repo_path / "feature_store.yaml"

# user-defined project name
replace_str_in_file(
feature_store_yaml_path, "project: my_project", f"project: {repo_name}"
)

# registry: replace relative path from template with absolute path
replace_str_in_file(
feature_store_yaml_path,
"registry: data/registry.db",
f"registry: {feature_repo_path}/data/registry.db",
)

# online store: replace relative path from template with absolute path
replace_str_in_file(
feature_store_yaml_path,
"path: data/online_store.db",
f"path: {feature_repo_path}/data/online_store.db",
)

# Remove the __pycache__ folder if it exists
import shutil

Expand Down
Loading