Spaces:
Running
Running
mike boone commited on
Commit ·
e343cfd
1
Parent(s): 7aff9ba
fix: normalize ThoughtSpot TML import object responses
Browse files
tests/test_liveboard_creation_context.py
CHANGED
|
@@ -147,3 +147,4 @@ def test_tml_504_recovery_verifies_state_before_retrying_full_payload():
|
|
| 147 |
assert "retrying full {retry_kind} payload once" in source
|
| 148 |
assert "connection_fqn=connection_fqn" in source
|
| 149 |
assert "wait_for_model_answer_ready" in source
|
|
|
|
|
|
| 147 |
assert "retrying full {retry_kind} payload once" in source
|
| 148 |
assert "connection_fqn=connection_fqn" in source
|
| 149 |
assert "wait_for_model_answer_ready" in source
|
| 150 |
+
assert 'if "status" in obj or "header" in obj' in source
|
thoughtspot_deployer.py
CHANGED
|
@@ -2346,18 +2346,31 @@ class ThoughtSpotDeployer:
|
|
| 2346 |
batch1_start = time.time()
|
| 2347 |
log_progress(f"Batch 1/2: Creating {table_count} tables...")
|
| 2348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2349 |
def _normalize_tml_import_objects(result):
|
| 2350 |
if isinstance(result, list):
|
| 2351 |
-
return result
|
| 2352 |
if isinstance(result, dict) and 'object' in result:
|
| 2353 |
-
return result['object']
|
| 2354 |
return None
|
| 2355 |
|
| 2356 |
def _tml_objects_by_name(expected_names, objects):
|
| 2357 |
named = {}
|
| 2358 |
for idx, obj in enumerate(objects or []):
|
| 2359 |
header = obj.get('response', {}).get('header', {}) if isinstance(obj, dict) else {}
|
| 2360 |
-
raw_name =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2361 |
table_name = (raw_name or (expected_names[idx] if idx < len(expected_names) else f"TABLE_{idx}")).upper()
|
| 2362 |
named[table_name] = obj
|
| 2363 |
return named
|
|
@@ -2449,12 +2462,23 @@ class ThoughtSpotDeployer:
|
|
| 2449 |
object_count = len(objects) if isinstance(objects, list) else 0
|
| 2450 |
object_statuses = []
|
| 2451 |
object_names = []
|
|
|
|
| 2452 |
for obj in objects or []:
|
| 2453 |
obj_response = obj.get('response', {}) if isinstance(obj, dict) else {}
|
| 2454 |
status = obj_response.get('status', {})
|
| 2455 |
header = obj_response.get('header', {})
|
| 2456 |
object_statuses.append(status.get('status_code'))
|
| 2457 |
-
object_names.append(header.get('name') or header.get('display_name'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2458 |
if _slog:
|
| 2459 |
_slog.log(
|
| 2460 |
"thoughtspot",
|
|
@@ -2465,6 +2489,7 @@ class ThoughtSpotDeployer:
|
|
| 2465 |
object_count=object_count,
|
| 2466 |
object_statuses=object_statuses,
|
| 2467 |
object_names=[name for name in object_names if name],
|
|
|
|
| 2468 |
)
|
| 2469 |
if objects is None:
|
| 2470 |
error = f"{phase_label} failed: Unexpected response format: {type(response_json)}"
|
|
|
|
| 2346 |
batch1_start = time.time()
|
| 2347 |
log_progress(f"Batch 1/2: Creating {table_count} tables...")
|
| 2348 |
|
| 2349 |
+
def _normalize_tml_import_object(obj):
|
| 2350 |
+
if not isinstance(obj, dict):
|
| 2351 |
+
return obj
|
| 2352 |
+
if "response" in obj:
|
| 2353 |
+
return obj
|
| 2354 |
+
if "status" in obj or "header" in obj:
|
| 2355 |
+
return {"response": obj}
|
| 2356 |
+
return obj
|
| 2357 |
+
|
| 2358 |
def _normalize_tml_import_objects(result):
|
| 2359 |
if isinstance(result, list):
|
| 2360 |
+
return [_normalize_tml_import_object(obj) for obj in result]
|
| 2361 |
if isinstance(result, dict) and 'object' in result:
|
| 2362 |
+
return [_normalize_tml_import_object(obj) for obj in result['object']]
|
| 2363 |
return None
|
| 2364 |
|
| 2365 |
def _tml_objects_by_name(expected_names, objects):
|
| 2366 |
named = {}
|
| 2367 |
for idx, obj in enumerate(objects or []):
|
| 2368 |
header = obj.get('response', {}).get('header', {}) if isinstance(obj, dict) else {}
|
| 2369 |
+
raw_name = (
|
| 2370 |
+
header.get('name')
|
| 2371 |
+
or header.get('display_name')
|
| 2372 |
+
or header.get('displayName')
|
| 2373 |
+
)
|
| 2374 |
table_name = (raw_name or (expected_names[idx] if idx < len(expected_names) else f"TABLE_{idx}")).upper()
|
| 2375 |
named[table_name] = obj
|
| 2376 |
return named
|
|
|
|
| 2462 |
object_count = len(objects) if isinstance(objects, list) else 0
|
| 2463 |
object_statuses = []
|
| 2464 |
object_names = []
|
| 2465 |
+
object_errors = []
|
| 2466 |
for obj in objects or []:
|
| 2467 |
obj_response = obj.get('response', {}) if isinstance(obj, dict) else {}
|
| 2468 |
status = obj_response.get('status', {})
|
| 2469 |
header = obj_response.get('header', {})
|
| 2470 |
object_statuses.append(status.get('status_code'))
|
| 2471 |
+
object_names.append(header.get('name') or header.get('display_name') or header.get('displayName'))
|
| 2472 |
+
if status.get('error_message'):
|
| 2473 |
+
object_errors.append(str(status.get('error_message'))[:300])
|
| 2474 |
+
status_summary = ", ".join(str(status) for status in object_statuses if status)
|
| 2475 |
+
if status_summary:
|
| 2476 |
+
log_progress(
|
| 2477 |
+
f" {phase_label}: response objects={object_count}; "
|
| 2478 |
+
f"statuses={status_summary}"
|
| 2479 |
+
)
|
| 2480 |
+
if object_errors:
|
| 2481 |
+
log_progress(f" {phase_label}: first object error: {object_errors[0]}")
|
| 2482 |
if _slog:
|
| 2483 |
_slog.log(
|
| 2484 |
"thoughtspot",
|
|
|
|
| 2489 |
object_count=object_count,
|
| 2490 |
object_statuses=object_statuses,
|
| 2491 |
object_names=[name for name in object_names if name],
|
| 2492 |
+
object_errors=object_errors[:5],
|
| 2493 |
)
|
| 2494 |
if objects is None:
|
| 2495 |
error = f"{phase_label} failed: Unexpected response format: {type(response_json)}"
|