EnxDev commented on code in PR #45100:
URL: https://github.com/apache/superset/pull/45100#discussion_r4224523376
##########
superset/semantic_layers/models.py:
##########
@@ -166,6 +168,55 @@ class ColumnMetadata:
extra: str | None = None
+_METADATA_IDENTITY_KEY: str = "semantic_layer_cache_identity"
+
+
+@dataclass
+class _MetadataCacheIdentity:
+ """Session-local identities, captured before discovery and forgotten on
Save."""
+
+ tokens: dict[uuid.UUID, str] = field(default_factory=dict)
+
+ @classmethod
+ def for_session(cls, session: Session) -> _MetadataCacheIdentity:
+ """Keep the memo's storage convention in one place."""
+ if _METADATA_IDENTITY_KEY not in session.info:
+ session.info[_METADATA_IDENTITY_KEY] = cls()
+ return cast(_MetadataCacheIdentity,
session.info[_METADATA_IDENTITY_KEY])
+
+ def capture(self, layer: SemanticLayer, session: Session) -> str:
+ """Web, task and MCP operations share a credential-independent
identity."""
+ if layer.uuid not in self.tokens:
+ namespace: str | Callable[[], str] = current_app.config.get(
+ "SEMANTIC_LAYER_CACHE_NAMESPACE", ""
+ )
+ if callable(namespace):
+ namespace = namespace()
+ if not isinstance(namespace, str):
+ raise TypeError(
+ "SEMANTIC_LAYER_CACHE_NAMESPACE must resolve to a string"
+ )
+ url: sa.engine.URL =
session.get_bind(mapper=SemanticLayer).engine.url
Review Comment:
For whoever reads the bot thread on this line: `Engine` does have an
`.engine` property that returns itself (SQLAlchemy 2.0.52 `engine/base.py`),
and `Connection` has one too. So `.engine.url` works whichever one `get_bind()`
hands back.
`test_version_token_is_captured_and_namespaced` and
`test_clear_discards_reused_implementation_objects` hit this path against a
real, unmocked SQLite session and pass, so I'd leave it as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]