codeant-ai-for-open-source[bot] commented on code in PR #43028:
URL: https://github.com/apache/superset/pull/43028#discussion_r3760375775
##########
tests/unit_tests/mcp_service/test_pooled_screenshot.py:
##########
@@ -17,20 +17,21 @@
from unittest.mock import MagicMock, patch
+import pytest
+
from superset.mcp_service.screenshot.pooled_screenshot import
PooledBaseScreenshot
-@patch("superset.mcp_service.screenshot.pooled_screenshot.retry_screenshot_operation")
-def test_get_screenshot_accepts_base_log_context(
- mock_retry_screenshot_operation: MagicMock,
-) -> None:
+def test_get_screenshot_raises_when_playwright_unavailable() -> None:
+ """get_screenshot raises RuntimeError when Playwright is unavailable."""
screenshot = PooledBaseScreenshot("http://example.com", "digest")
user = MagicMock()
- screenshot.get_screenshot(user, log_context="cache_key=abc")
-
- mock_retry_screenshot_operation.assert_called_once_with(
- screenshot._get_screenshot_internal, # pylint:
disable=protected-access
- user,
- None,
- )
+ with patch("superset.mcp_service.screenshot.pooled_screenshot.super") as
mock_super:
+ mock_super_instance = MagicMock()
+ mock_super.return_value = mock_super_instance
+ mock_super_instance.get_screenshot.side_effect = RuntimeError(
+ "Playwright is required"
+ )
Review Comment:
**Suggestion:** The test does not actually simulate Playwright being
unavailable: it patches the module's `super` lookup and makes the mocked
superclass raise the expected error. Consequently, this test passes even if
`PooledBaseScreenshot` fails to propagate the real `PLAYWRIGHT_AVAILABLE`
failure or bypasses the Playwright availability check entirely. Patch the
actual availability state (or the concrete superclass implementation without
replacing `super`) and verify the real code path raises. [possible bug]
<details>
<summary><b>Severity Level:</b> Minor ๐งน</summary>
```mdx
- โ ๏ธ Availability regression can pass unit tests undetected.
- โ ๏ธ Screenshot failure coverage does not validate Playwright configuration.
- โ Reports and thumbnails may fail only after deployment.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e4afb19ed10247a8a3b34db45ad86f8d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=e4afb19ed10247a8a3b34db45ad86f8d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/test_pooled_screenshot.py
**Line:** 30:35
**Comment:**
*Possible Bug: The test does not actually simulate Playwright being
unavailable: it patches the module's `super` lookup and makes the mocked
superclass raise the expected error. Consequently, this test passes even if
`PooledBaseScreenshot` fails to propagate the real `PLAYWRIGHT_AVAILABLE`
failure or bypasses the Playwright availability check entirely. Patch the
actual availability state (or the concrete superclass implementation without
replacing `super`) and verify the real code path raises.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43028&comment_hash=f0e7bef3890a88f1480e0d8cd28d3f5ce44609e7a583e64830ea01fc38fbe883&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43028&comment_hash=f0e7bef3890a88f1480e0d8cd28d3f5ce44609e7a583e64830ea01fc38fbe883&reaction=dislike'>๐</a>
##########
superset/tasks/cache.py:
##########
@@ -397,21 +397,17 @@ def cache_warmup(
return results
- wd: WebDriverSelenium = WebDriverSelenium(
- current_app.config["WEBDRIVER_TYPE"], user=user
+ wd: WebDriverPlaywright = WebDriverPlaywright(
+ "", current_app.config["WEBDRIVER_WINDOW"]["dashboard"]
)
- try:
- for url in strategy.get_urls():
- try:
- logger.info("Fetching %s", url)
- wd.get_screenshot(url, "grid-container")
- results["success"].append(url)
- except Exception: # noqa: BLE001
- logger.exception("Error warming up cache for %s", url)
- results["errors"].append(url)
- finally:
- # Ensure WebDriver is properly cleaned up
- wd.destroy()
+ for url in strategy.get_urls():
+ try:
+ logger.info("Fetching %s", url)
+ wd.get_screenshot(url, "grid-container", user=user)
+ results["success"].append(url)
Review Comment:
**Suggestion:** The return value from `get_screenshot` is ignored, but that
method can return `None` after handling a `PlaywrightError` internally. Such
URLs are therefore marked as successful even though no screenshot was captured
and the cache was not warmed. Treat a falsey screenshot result as an error
instead of appending the URL to `success`. [logic error]
<details>
<summary><b>Severity Level:</b> Minor ๐งน</summary>
```mdx
- โ ๏ธ Cache-warmup results hide Playwright capture failures.
- โ ๏ธ Operators may believe dashboard warmups succeeded.
- โ ๏ธ Failed dashboard rendering is absent from `results["errors"]`.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aa5b6ed3088d4cd68c4f170aaf5510be&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=aa5b6ed3088d4cd68c4f170aaf5510be&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/tasks/cache.py
**Line:** 407:408
**Comment:**
*Logic Error: The return value from `get_screenshot` is ignored, but
that method can return `None` after handling a `PlaywrightError` internally.
Such URLs are therefore marked as successful even though no screenshot was
captured and the cache was not warmed. Treat a falsey screenshot result as an
error instead of appending the URL to `success`.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43028&comment_hash=cd76e6ec5bfbc04b256627055374d405c0a5fbd47082053427fd886a628bdef4&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43028&comment_hash=cd76e6ec5bfbc04b256627055374d405c0a5fbd47082053427fd886a628bdef4&reaction=dislike'>๐</a>
##########
superset/utils/webdriver.py:
##########
@@ -94,39 +79,8 @@
def check_playwright_availability() -> bool:
- """
- Lightweight check for Playwright availability.
-
- First checks if browser binary exists, falls back to launch test if needed.
- """
- if sync_playwright is None:
- return False
-
- try:
- with sync_playwright() as p:
- # First try lightweight check - just verify executable exists
- try:
- executable_path = p.chromium.executable_path
- if executable_path:
- return True
- except Exception:
- # Fall back to full launch test if executable_path fails
- logger.debug(
- "Executable path check failed, falling back to launch test"
- )
-
- # Fallback: actually launch browser to ensure it works
- browser = p.chromium.launch(headless=True)
- browser.close()
- return True
- except Exception as e:
- logger.warning(
- "Playwright module is installed but browser launch failed. "
- "Run 'playwright install chromium' to install browser binaries. "
- "Error: %s",
- str(e),
- )
- return False
+ """Check Playwright availability by verifying the module is importable."""
+ return sync_playwright is not None
Review Comment:
**Suggestion:** `check_playwright_availability` only verifies that the
Python module can be imported, not that a browser executable is installed and
launchable. When `pip install playwright` has been run without `playwright
install chromium`, this returns `True`, then `_browser_manager.get_browser`
fails during launch with a lower-level executable error instead of the explicit
installation error intended by `get_screenshot`. The availability check should
also validate browser launchability or handle this launch failure with the same
actionable installation message. [possible bug]
<details>
<summary><b>Severity Level:</b> Major โ ๏ธ</summary>
```mdx
- โ Reports fail when Chromium is not installed.
- โ Thumbnail generation fails in the same environment.
- โ ๏ธ Operators receive less actionable setup diagnostics.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=df2f14c37765464e97092fbaea0ca4ad&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=df2f14c37765464e97092fbaea0ca4ad&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/utils/webdriver.py
**Line:** 82:84
**Comment:**
*Possible Bug: `check_playwright_availability` only verifies that the
Python module can be imported, not that a browser executable is installed and
launchable. When `pip install playwright` has been run without `playwright
install chromium`, this returns `True`, then `_browser_manager.get_browser`
fails during launch with a lower-level executable error instead of the explicit
installation error intended by `get_screenshot`. The availability check should
also validate browser launchability or handle this launch failure with the same
actionable installation message.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43028&comment_hash=e68d1a65f5c124a7e75e3291ff1f63f775db46ac87a2fd65eae14bf596f12668&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43028&comment_hash=e68d1a65f5c124a7e75e3291ff1f63f775db46ac87a2fd65eae14bf596f12668&reaction=dislike'>๐</a>
--
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]