diff --git a/singer_sdk/streams/sql.py b/singer_sdk/streams/sql.py index 3d3de5bbe..7a3fe3886 100644 --- a/singer_sdk/streams/sql.py +++ b/singer_sdk/streams/sql.py @@ -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, @@ -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. @@ -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: