rusackas opened a new pull request, #41881:
URL: https://github.com/apache/superset/pull/41881
### SUMMARY
`Python-Unit` has been intermittently failing on master's `unit-tests
(previous)` job (Python 3.10) since ~2026-07-07T16:51, with:
```
AttributeError: <function list_metrics at 0x...> does not have the attribute
'DatasetDAO'
```
Root cause: `superset/mcp_service/semantic_layer/tool/__init__.py`
re-exports the `list_metrics` function under the same name as its defining
submodule:
```python
from superset.mcp_service.semantic_layer.tool.list_metrics import (
list_metrics,
)
```
This overwrites the `tool.list_metrics` package attribute (originally set to
the submodule by Python's import machinery) with the function object.
`tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.py` patches
`DatasetDAO`/`SemanticViewDAO`/`db` via the dotted string
`"superset.mcp_service.semantic_layer.tool.list_metrics.DatasetDAO"`. On Python
3.10, `unittest.mock`'s target resolution (`_importer`) walks the dotted path
via plain `getattr`, so it resolves `tool.list_metrics` to the shadowed
function instead of the submodule, then fails looking up `DatasetDAO` on it.
This was fixed in a later CPython version (mock's resolution now prefers
importing the submodule directly), so the bug only reproduces on 3.10 — hence
the flip-flopping pass/fail pattern across the Python version matrix.
Confirmed with a minimal repro locally: fails identically on Python 3.10.14,
passes on 3.13.0a5.
The fix switches the affected patches to `patch.object(list_metrics_module,
"X")` against the module reference this file already imports at the top
(`importlib.import_module(...)`) — the same pattern this file already uses for
`user_can_view_data_model_metadata`. This sidesteps the ambiguous string
resolution entirely rather than depending on Python-version-specific mock
internals.
Checked sibling test files in the same package (`test_get_table.py`,
`test_get_compatible_metrics.py`, `test_get_compatible_dimensions.py`) for the
same footgun — they patch DAOs at their defining module (e.g.
`superset.daos.dataset.DatasetDAO`) rather than through the re-exporting
package, so they're unaffected.
### TESTING INSTRUCTIONS
On Python 3.10:
```
pytest tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.py
-v
```
Previously failed 6 tests with the `AttributeError` above; should now pass.
`pre-commit run --files
tests/unit_tests/mcp_service/semantic_layer/tool/test_list_metrics.py` passes
clean (ruff, mypy).
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]