diff --git a/sdk/python/feast/errors.py b/sdk/python/feast/errors.py index 84a9f12ec4..abd195f8a3 100644 --- a/sdk/python/feast/errors.py +++ b/sdk/python/feast/errors.py @@ -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__( diff --git a/sdk/python/feast/repo_config.py b/sdk/python/feast/repo_config.py index 185a8723ad..f231071a79 100644 --- a/sdk/python/feast/repo_config.py +++ b/sdk/python/feast/repo_config.py @@ -20,6 +20,7 @@ from feast.errors import ( FeastFeatureServerTypeInvalidError, + FeastFileRegistryPathNotAbsoluteError, FeastInvalidAuthConfigClass, FeastOfflineStoreInvalidName, FeastOnlineStoreInvalidName, @@ -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 diff --git a/sdk/python/feast/repo_operations.py b/sdk/python/feast/repo_operations.py index 4db0bbc6fd..ef45bbafa6 100644 --- a/sdk/python/feast/repo_operations.py +++ b/sdk/python/feast/repo_operations.py @@ -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