Skip to content

Commit

Permalink
Fix bug in allowing empty repositories to be applied to a GCS registry (
Browse files Browse the repository at this point in the history
#1488)

* Fix no-op for GCS registry

Signed-off-by: Willem Pienaar <git@willem.co>

* Unify signature

Signed-off-by: Willem Pienaar <git@willem.co>
  • Loading branch information
woop committed Apr 21, 2021
1 parent e95208b commit cf7dd2e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sdk/python/feast/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit cf7dd2e

Please sign in to comment.