From 5a2379b50b019c5ec5f8060ea0f660f536f3a0f7 Mon Sep 17 00:00:00 2001 From: Willem Pienaar <6728866+woop@users.noreply.github.com> Date: Wed, 21 Apr 2021 12:59:47 -0700 Subject: [PATCH] Fix bug in allowing empty repositories to be applied to a GCS registry (#1488) * Fix no-op for GCS registry Signed-off-by: Willem Pienaar * Unify signature Signed-off-by: Willem Pienaar --- sdk/python/feast/registry.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sdk/python/feast/registry.py b/sdk/python/feast/registry.py index 473de1b49c..8832ea9f94 100644 --- a/sdk/python/feast/registry.py +++ b/sdk/python/feast/registry.py @@ -20,8 +20,6 @@ from typing import Callable, List, Optional from urllib.parse import urlparse -from google.auth.exceptions import DefaultCredentialsError - from feast.entity import Entity from feast.errors import ( EntityNotFoundException, @@ -71,7 +69,7 @@ def __init__(self, registry_path: str, repo_path: Path, cache_ttl: timedelta): def _initialize_registry(self): """Explicitly forces the initialization of a registry""" - self._registry_store.update_registry_proto() + self._registry_store.update_registry_proto(updater=None) def apply_entity(self, entity: Entity, project: str): """ @@ -377,7 +375,9 @@ def get_registry_proto(self): pass @abstractmethod - def update_registry_proto(self, updater: Callable[[RegistryProto], RegistryProto]): + def update_registry_proto( + self, updater: Optional[Callable[[RegistryProto], RegistryProto]] = None + ): """ Updates the registry using the function passed in. If the registry proto has not been created yet this method will create it. This method writes to the registry path. @@ -406,7 +406,7 @@ def get_registry_proto(self): ) def update_registry_proto( - self, updater: Callable[[RegistryProto], RegistryProto] = None + self, updater: Optional[Callable[[RegistryProto], RegistryProto]] = None ): try: registry_proto = self.get_registry_proto() @@ -431,6 +431,7 @@ def _write_registry(self, registry_proto: RegistryProto): class GCSRegistryStore(RegistryStore): def __init__(self, uri: str): try: + from google.auth.exceptions import DefaultCredentialsError from google.cloud import storage except ImportError: # TODO: Ensure versioning depends on requirements.txt/setup.py and isn't hardcoded @@ -470,13 +471,16 @@ def get_registry_proto(self): f'Registry not found at path "{self._uri.geturl()}". Have you run "feast apply"?' ) - def update_registry_proto(self, updater: Callable[[RegistryProto], RegistryProto]): + def update_registry_proto( + self, updater: Optional[Callable[[RegistryProto], RegistryProto]] = None + ): try: registry_proto = self.get_registry_proto() except FileNotFoundError: registry_proto = RegistryProto() registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION - registry_proto = updater(registry_proto) + if updater: + registry_proto = updater(registry_proto) self._write_registry(registry_proto) return