Skip to content

Commit c1baa0e

Browse files
author
ci bot
committed
Merge branch 'misc-fixes' into 'enterprise'
fix: standalone and bigquery fixes + streamlit warning suppression See merge request dkinternal/testgen/dataops-testgen!503
2 parents ad79b73 + e91277e commit c1baa0e

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

testgen/__main__.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
# Silence streamlit's "missing ScriptRunContext" / "No runtime found" /
2+
# "Session state does not function" warnings, which fire whenever streamlit-
3+
# decorated code runs outside an active script run (our CLI, scheduler, server,
4+
# and any import that touches @st.cache_data). Must run before the first
5+
# streamlit-using import, so it sits at the top of the module.
6+
#
7+
# We replace ``set_log_level`` itself, after seeding it to "error". Streamlit's
8+
# own ``_update_logger`` callback fires on config parse and would otherwise
9+
# downgrade us back to "info"; the cap floors any later call at ERROR.
10+
def _silence_streamlit_logs() -> None:
11+
import logging as _logging
12+
13+
try:
14+
from streamlit import logger as _st_logger
15+
except ImportError:
16+
return
17+
18+
_original = _st_logger.set_log_level
19+
_original("error")
20+
21+
def _capped(level):
22+
if isinstance(level, str):
23+
try:
24+
level_num = getattr(_logging, level.upper())
25+
except AttributeError:
26+
_original(level)
27+
return
28+
else:
29+
level_num = level
30+
_original(max(level_num, _logging.ERROR))
31+
32+
_st_logger.set_log_level = _capped
33+
34+
35+
_silence_streamlit_logs()
36+
37+
138
import base64
239
import importlib
340
import logging
@@ -566,14 +603,21 @@ def generate_secret(length: int = 12) -> str:
566603

567604
# Persist caller-supplied runtime overrides (ports, TLS) so they apply to
568605
# subsequent `testgen run-app` invocations.
569-
persisted_env_vars = ("TG_UI_PORT", "TG_API_PORT", "SSL_CERT_FILE", "SSL_KEY_FILE")
606+
persisted_env_vars = ("TG_UI_PORT", "TG_API_PORT", "TESTGEN_LOG_FILE_PATH", "SSL_CERT_FILE", "SSL_KEY_FILE")
570607
persisted_lines = [f"{name}={os.environ[name]}" for name in persisted_env_vars if os.environ.get(name)]
571608
if persisted_lines:
572609
config_lines.extend(["", "# Runtime overrides from installer", *persisted_lines])
573610

574611
config_path.write_text("\n".join(config_lines) + "\n")
575612
click.echo(f"Config written to {config_path}")
576613

614+
# `getenv` resolves env vars before config.env, so a pre-existing
615+
# TESTGEN_USERNAME / TESTGEN_PASSWORD in the shell would override the
616+
# CLI-supplied values and get seeded into the DB. Force the CLI args
617+
# to win for the rest of this process.
618+
os.environ["TESTGEN_USERNAME"] = username
619+
os.environ["TESTGEN_PASSWORD"] = password
620+
577621
# Reload settings — the module was already evaluated at import time
578622
# before the config file existed. Reloading re-reads the new file
579623
# and re-evaluates all module-level variables.
@@ -895,6 +939,7 @@ def init_ui():
895939
"run",
896940
app_file,
897941
"--browser.gatherUsageStats=false",
942+
f"--logger.level={'debug' if settings.IS_DEBUG else 'error'}",
898943
"--client.showErrorDetails=none",
899944
"--client.toolbarMode=minimal",
900945
"--server.enableStaticServing=true",

testgen/template/dbsetup_test_types/test_types_Freshness_Trend.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test_types:
6666
fingerprint AS result_measure,
6767
CASE
6868
-- Training mode: tolerances not yet calculated
69-
WHEN {LOWER_TOLERANCE} IS NULL AND {UPPER_TOLERANCE} IS NULL THEN -1
69+
WHEN CAST({LOWER_TOLERANCE} AS FLOAT64) IS NULL AND CAST({UPPER_TOLERANCE} AS FLOAT64) IS NULL THEN -1
7070
-- No change and excluded day: suppress
7171
WHEN fingerprint = '{BASELINE_VALUE}' AND {IS_EXCLUDED_DAY} = 1 THEN 1
7272
-- No change, beyond time range (business time): LATE
@@ -75,14 +75,14 @@ test_types:
7575
-- Table changed outside time range (business time): UNEXPECTED
7676
WHEN fingerprint <> '{BASELINE_VALUE}'
7777
AND NOT (interval_minutes - {EXCLUDED_MINUTES})
78-
BETWEEN {LOWER_TOLERANCE} AND {UPPER_TOLERANCE} THEN 0
78+
BETWEEN CAST({LOWER_TOLERANCE} AS FLOAT64) AND CAST({UPPER_TOLERANCE} AS FLOAT64) THEN 0
7979
ELSE 1
8080
END AS result_code,
8181
'Table update detected: ' || CASE WHEN fingerprint <> '{BASELINE_VALUE}' THEN 'Yes' ELSE 'No' END
8282
|| CASE
83-
WHEN fingerprint <> '{BASELINE_VALUE}' AND (interval_minutes - {EXCLUDED_MINUTES}) BETWEEN {LOWER_TOLERANCE} AND {UPPER_TOLERANCE} THEN '. On time.'
84-
WHEN fingerprint <> '{BASELINE_VALUE}' AND (interval_minutes - {EXCLUDED_MINUTES}) < {LOWER_TOLERANCE} THEN '. Earlier than expected.'
85-
WHEN fingerprint <> '{BASELINE_VALUE}' AND (interval_minutes - {EXCLUDED_MINUTES}) > {UPPER_TOLERANCE} THEN '. Later than expected.'
83+
WHEN fingerprint <> '{BASELINE_VALUE}' AND (interval_minutes - {EXCLUDED_MINUTES}) BETWEEN CAST({LOWER_TOLERANCE} AS FLOAT64) AND CAST({UPPER_TOLERANCE} AS FLOAT64) THEN '. On time.'
84+
WHEN fingerprint <> '{BASELINE_VALUE}' AND (interval_minutes - {EXCLUDED_MINUTES}) < CAST({LOWER_TOLERANCE} AS FLOAT64) THEN '. Earlier than expected.'
85+
WHEN fingerprint <> '{BASELINE_VALUE}' AND (interval_minutes - {EXCLUDED_MINUTES}) > CAST({UPPER_TOLERANCE} AS FLOAT64) THEN '. Later than expected.'
8686
WHEN fingerprint = '{BASELINE_VALUE}' AND {IS_EXCLUDED_DAY} = 0 AND (interval_minutes - {EXCLUDED_MINUTES}) > {THRESHOLD_VALUE} THEN '. Late.'
8787
ELSE ''
8888
END AS result_message,

0 commit comments

Comments
 (0)