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

Fix bug in allowing empty repositories to be applied to a GCS registry #1488

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't need updater=None since you added the default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this was a relic from my debugging. Good catch.


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