Skip to content

Commit

Permalink
suggestion: add additional handling in _get_registry_cache()
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers authored Oct 28, 2024
1 parent d230135 commit 3451dec
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions airbyte/sources/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

from airbyte import exceptions as exc
from airbyte._util.meta import is_docker_installed
from airbyte.constants import AIRBYTE_OFFLINE_MODE
from airbyte.version import get_version

from airbyte.logs import warn_once

__cache: dict[str, ConnectorMetadata] | None = None

Expand Down Expand Up @@ -233,7 +234,14 @@ def _get_registry_cache(*, force_refresh: bool = False) -> dict[str, ConnectorMe
return __cache

registry_url = _get_registry_url()
if registry_url.upper() in ["0", "F", "FALSE"]:
# User has disabled the registry. Return an empty dictionary:
return {}
if registry_url.startswith("http"):
if AIRBYTE_OFFLINE_MODE:
# Remote requests dissalowed. Return an empty dictionary:
return {}

response = requests.get(
registry_url,
headers={"User-Agent": f"PyAirbyte/{get_version()}"},
Expand All @@ -256,11 +264,11 @@ def _get_registry_cache(*, force_refresh: bool = False) -> dict[str, ConnectorMe
new_cache[connector_metadata.name] = connector_metadata

if len(new_cache) == 0:
raise exc.PyAirbyteInternalError(
message="Connector registry is empty.",
context={
"registry_url": _get_registry_url(),
},
# This isn't necessarily fatal, since users can bring their own
# connector definitions.
warn_once(
message=f"Connector registry is empty: {registry_url}",
with_stack=False,
)

__cache = new_cache
Expand Down

0 comments on commit 3451dec

Please sign in to comment.