032: fix async chain for target schema check + mapper + executor
resolve_database_id → async (was sync but called async SupersetClient methods) - await client.get_database(db_id) - await client.get_databases(...) validate_target_table_schema → async (calls async resolve_database_id + execute_and_poll) - await executor.resolve_database_id(...) - await executor.execute_and_poll(...) Route check_target_schema → await validate_target_table_schema(...) MapperPlugin.execute → await executor.resolve_database_id(...) (execute() was already async def, just missing await) SupersetSqlLabExecutor.execute_sql → await self.resolve_database_id() (was sync call to now-async method)
This commit is contained in:
@@ -269,7 +269,7 @@ async def check_target_schema(
|
||||
extra={"src": "translate_routes"},
|
||||
)
|
||||
try:
|
||||
result = validate_target_table_schema(payload, config_manager)
|
||||
result = await validate_target_table_schema(payload, config_manager)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.explore("check_target_schema failed",
|
||||
|
||||
@@ -167,7 +167,7 @@ class MapperPlugin(PluginBase):
|
||||
if not database_id:
|
||||
log.error("database_id is required for sqllab source.")
|
||||
raise ValueError("database_id is required for sqllab source.")
|
||||
executor.resolve_database_id(target_database_id=str(database_id))
|
||||
await executor.resolve_database_id(target_database_id=str(database_id))
|
||||
|
||||
mapper.run_mapping(
|
||||
superset_client=client,
|
||||
|
||||
@@ -189,7 +189,7 @@ def _parse_sqllab_result(result: dict[str, Any]) -> tuple[list[dict[str, Any]],
|
||||
# @RELATION DEPENDS_ON -> [_extract_columns_from_rows]
|
||||
# @RELATION DEPENDS_ON -> [_parse_sqllab_result]
|
||||
# @RELATION DEPENDS_ON -> [SupersetSqlLabExecutor]
|
||||
def validate_target_table_schema(
|
||||
async def validate_target_table_schema(
|
||||
req: TargetSchemaValidationRequest,
|
||||
config_manager: ConfigManager,
|
||||
) -> TargetSchemaValidationResponse:
|
||||
@@ -238,7 +238,7 @@ def validate_target_table_schema(
|
||||
|
||||
try:
|
||||
executor = SupersetSqlLabExecutor(config_manager, req.environment_id)
|
||||
executor.resolve_database_id(target_database_id=req.target_database_id)
|
||||
await executor.resolve_database_id(target_database_id=req.target_database_id)
|
||||
backend = executor.get_database_backend() or ""
|
||||
db_name = executor.get_database_name() or "unknown"
|
||||
|
||||
@@ -290,7 +290,7 @@ def validate_target_table_schema(
|
||||
logger.reason("Executing SQL Lab query",
|
||||
extra={"payload": {"sql": sql[:200], "backend": backend, "database_name": db_name}})
|
||||
|
||||
result = executor.execute_and_poll(sql=sql, max_polls=15, poll_interval_seconds=1.0)
|
||||
result = await executor.execute_and_poll(sql=sql, max_polls=15, poll_interval_seconds=1.0)
|
||||
status = result.get("status", "")
|
||||
|
||||
if status == "failed":
|
||||
|
||||
@@ -58,7 +58,7 @@ class SupersetSqlLabExecutor:
|
||||
# @PRE database_name or database_id should be known.
|
||||
# @POST Returns database_id integer or raises ValueError. Also sets self._database_backend.
|
||||
# @SIDE_EFFECT Fetches databases list from Superset; optionally fetches single DB for backend.
|
||||
def resolve_database_id(
|
||||
async def resolve_database_id(
|
||||
self,
|
||||
database_name: str | None = None,
|
||||
target_database_id: str | None = None,
|
||||
@@ -71,7 +71,7 @@ class SupersetSqlLabExecutor:
|
||||
try:
|
||||
db_id = int(target_database_id)
|
||||
# Fetch full DB info to get backend
|
||||
db_info = client.get_database(db_id)
|
||||
db_info = await client.get_database(db_id)
|
||||
result = db_info.get("result", db_info)
|
||||
self._database_id = result.get("id", db_id)
|
||||
self._database_backend = result.get("backend") or result.get("engine")
|
||||
@@ -92,7 +92,7 @@ class SupersetSqlLabExecutor:
|
||||
# Fall through to default resolution
|
||||
|
||||
# Fetch full database list with backend info
|
||||
_, databases = client.get_databases(
|
||||
_, databases = await client.get_databases(
|
||||
query={"columns": ["id", "database_name", "backend"]}
|
||||
)
|
||||
if not databases:
|
||||
@@ -156,7 +156,7 @@ class SupersetSqlLabExecutor:
|
||||
client = self._get_client()
|
||||
db_id = database_id or self._database_id
|
||||
if not db_id:
|
||||
db_id = self.resolve_database_id()
|
||||
db_id = await self.resolve_database_id()
|
||||
|
||||
logger.reason("Submitting SQL to Superset SQL Lab", {
|
||||
"database_id": db_id,
|
||||
|
||||
Reference in New Issue
Block a user