Skip to content

Commit be36c20

Browse files
authored
Merge pull request #97 from datakind/develop
feat: added option for api auth
2 parents 47129ef + 715019b commit be36c20

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

src/webapp/databricks.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from .config import databricks_vars, gcs_vars
99
from .utilities import databricksify_inst_name, SchemaType
1010
from typing import List, Any
11-
import time
1211

1312
# List of data medallion levels
1413
MEDALLION_LEVELS = ["silver", "gold", "bronze"]
@@ -222,36 +221,20 @@ def fetch_table_data(
222221
warehouse_id=warehouse_id,
223222
statement=sql,
224223
format=Format.JSON_ARRAY,
225-
wait_timeout="10s",
226-
on_wait_timeout=ExecuteStatementRequestOnWaitTimeout.CONTINUE,
224+
wait_timeout="30s",
225+
on_wait_timeout=ExecuteStatementRequestOnWaitTimeout.CANCEL,
227226
)
228227

229-
status = getattr(resp, "status", None)
230-
if status and status.state == "SUCCEEDED" and getattr(resp, "result", None):
231-
# resp.results is a list of row‐arrays, resp.schema is a list of column metadata
232-
column_names = [col.name for col in resp.manifest.schema]
233-
rows = resp.result.data_array
234-
else:
235-
# A. If the SQL didn’t finish in 10 seconds, resp.statement_id will be set.
236-
stmt_id = getattr(resp, "statement_id", None)
237-
if not stmt_id:
238-
raise ValueError(
239-
f"fetch_table_data(): unexpected response state: {resp}"
240-
)
228+
if not resp or not getattr(resp, "status", None):
229+
raise ValueError("fetch_table_data(): invalid response or missing status")
241230

242-
# B. Poll until the statement succeeds (or fails/cancels)
243-
status = resp.status.state if getattr(resp, "status", None) else None
244-
while status not in ("SUCCEEDED", "FAILED", "CANCELED"):
245-
time.sleep(1)
246-
resp2 = w.statement_execution.get_statement(statement_id=stmt_id)
247-
status = resp2.status.state if getattr(resp2, "status", None) else None
248-
resp = resp2
249-
if status != "SUCCEEDED":
250-
raise ValueError(f"fetch_table_data(): query ended with state {status}")
231+
if resp.status.state != "SUCCEEDED":
232+
raise ValueError(
233+
f"fetch_table_data(): query failed with state {resp.status.state}"
234+
)
251235

252-
# C. At this point, resp holds the final manifest and first chunk
253-
column_names = [col.name for col in resp.manifest.schema]
254-
rows = resp.result.data_array
236+
# Extract rows
237+
column_names = [col.name for col in resp.manifest.schema]
238+
rows = resp.result.data_array
255239

256-
# Transform each row (a list of values) into a dict
257240
return [dict(zip(column_names, row)) for row in rows]

src/webapp/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import secrets
77
from fastapi import FastAPI, Depends, HTTPException, status, Security
88
from fastapi.responses import FileResponse
9-
from fastapi.security import OAuth2PasswordRequestForm
109
from pydantic import BaseModel
1110
from sqlalchemy.future import select
1211
from sqlalchemy import update
@@ -38,7 +37,6 @@
3837
create_access_token,
3938
get_api_key,
4039
get_api_key_hash,
41-
check_creds,
4240
)
4341

4442
# Set the logging

src/webapp/main_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
get_session,
1414
ApiKeyTable,
1515
)
16-
from unittest.mock import patch
1716
from .authn import get_password_hash, get_api_key_hash
1817
from .test_helper import (
1918
DATAKINDER,

0 commit comments

Comments
 (0)