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

refactor(taps): Change SQLStream.schema into a cached property #1745

Merged
11 changes: 9 additions & 2 deletions singer_sdk/streams/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SQLStream(Stream, metaclass=abc.ABCMeta):
"""Base class for SQLAlchemy-based streams."""

connector_class = SQLConnector
_cached_schema: dict | None = None

def __init__(
self,
Expand Down Expand Up @@ -74,7 +75,7 @@ def metadata(self) -> MetadataMapping:
"""
return self._singer_catalog_entry.metadata

@property
@property # TODO: Investigate @cached_property after py > 3.7
def schema(self) -> dict:
"""Return metadata object (dict) as specified in the Singer spec.

Expand All @@ -83,7 +84,13 @@ def schema(self) -> dict:
Returns:
The schema object.
"""
return t.cast(dict, self._singer_catalog_entry.schema.to_dict())
if not self._cached_schema:
self._cached_schema = t.cast(
dict,
self._singer_catalog_entry.schema.to_dict(),
)

return self._cached_schema

@property
def tap_stream_id(self) -> str:
Expand Down