YuriyKrasilnikov commented on PR #37516:
URL: https://github.com/apache/superset/pull/37516#issuecomment-3809903143
## Fixed in b8d12f32bb
### 1. `bool` as `int` — spurious metric emission
`isinstance(True, (int, float))` evaluates to `True` (bool is a subclass of
int), so `timing["is_cached"]` was emitted as
`stats_logger.timing("chart_data.is_cached", 0.001)`.
Fix:
```python
if isinstance(value, (int, float)) and not isinstance(value, bool):
stats_logger.timing(f"chart_data.{phase}", value / 1000)
```
### 2. `STATS_LOGGER` KeyError
Direct dict access `current_app.config["STATS_LOGGER"]` raises `KeyError`
when the key is absent.
Fix:
```python
stats_logger = current_app.config.get("STATS_LOGGER")
if stats_logger and hasattr(stats_logger, "timing"):
```
### 3. Tests — explicit `current_app` mock
All 5 tests now explicitly mock `current_app.config` instead of relying on
implicit app context:
```python
with patch("superset.common.query_context_processor.current_app") as
mock_app:
mock_app.config = {
"STATS_LOGGER": MagicMock(),
"CHART_DATA_SLOW_QUERY_THRESHOLD_MS": None,
}
```
All 5 tests pass.
--
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]