bito-code-review[bot] commented on code in PR #38576:
URL: https://github.com/apache/superset/pull/38576#discussion_r3416231293


##########
superset/dashboards/api.py:
##########
@@ -1471,7 +1471,6 @@ def build_response(status_code: int) -> WerkzeugResponse:
 
         if cache_payload.should_trigger_task(force):
             logger.info("Triggering screenshot ASYNC")
-            screenshot_obj.cache.set(cache_key, 
ScreenshotCachePayload().to_dict())
             cache_dashboard_screenshot.delay(

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Inconsistent API pattern across modules</b></div>
   <div id="fix">
   
   The diff introduces inconsistency between dashboards/api.py and 
charts/api.py. charts/api.py (lines 661, 805) still has the cache.set calls 
before triggering async tasks, while dashboards/api.py removes them. This 
divergence increases maintenance burden and may confuse developers about the 
expected pattern.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1823a5</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
superset/tasks/thumbnails.py:
##########
@@ -90,6 +93,9 @@ def cache_dashboard_thumbnail(
     dashboard = Dashboard.get(dashboard_id)
     url = get_url_path("Superset.dashboard", dashboard_id_or_slug=dashboard.id)
 
+    screenshot = DashboardScreenshot(url, dashboard.digest)
+    resolved_cache_key = cache_key or screenshot.get_cache_key(window_size, 
thumb_size)

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Unused variable in diff</b></div>
   <div id="fix">
   
   Variable `resolved_cache_key` is assigned but never read. The 
`compute_and_cache` method already resolves the cache key internally 
(`cache_key = cache_key or self.get_cache_key(window_size, thumb_size)`), 
making this line dead code that creates maintenance confusion.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    --- a/superset/tasks/thumbnails.py
    +++ b/superset/tasks/thumbnails.py
    @@ -94,7 +94,6 @@ def cache_dashboard_thumbnail(
         url = get_url_path("Superset.dashboard", 
dashboard_id_or_slug=dashboard.id)
    
         screenshot = DashboardScreenshot(url, dashboard.digest)
    -    resolved_cache_key = cache_key or 
screenshot.get_cache_key(window_size, thumb_size)
    
         logger.info("Caching dashboard: %s", url)
         _, username = get_executor(
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1823a5</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
tests/unit_tests/tasks/test_thumbnails.py:
##########
@@ -0,0 +1,134 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+
[email protected]
+def mock_thumbnail_cache():
+    with patch("superset.tasks.thumbnails.thumbnail_cache", True):
+        yield
+
+
[email protected]
+def mock_dashboard():
+    dashboard = MagicMock()
+    dashboard.id = 1
+    dashboard.digest = "test_digest"
+    return dashboard
+
+
+def _make_screenshot_mock(cache_key: str = "test_cache_key") -> MagicMock:
+    screenshot = MagicMock()
+    screenshot.get_cache_key.return_value = cache_key
+    return screenshot
+
+
+# ---------------------------------------------------------------------------
+# Helpers shared across tests
+# ---------------------------------------------------------------------------
+
+_COMMON_PATCHES = [
+    "superset.tasks.thumbnails.get_executor",
+    "superset.tasks.thumbnails.security_manager",
+    "superset.tasks.thumbnails.override_user",
+    "superset.tasks.thumbnails.get_url_path",
+    "superset.tasks.thumbnails.DashboardScreenshot",
+]
+
+
+def _apply_patches(fn):
+    """Stack the five common patches onto a test function."""
+    for p in reversed(_COMMON_PATCHES):
+        fn = patch(p)(fn)
+    return fn
+
+
+# ---------------------------------------------------------------------------
+# Tests
+# ---------------------------------------------------------------------------
+
+
+@patch("superset.tasks.thumbnails.thumbnail_cache", None)
+def test_cache_dashboard_thumbnail_skips_when_no_cache():
+    """Task exits early when no thumbnail cache is configured."""
+    from superset.tasks.thumbnails import cache_dashboard_thumbnail
+
+    result = cache_dashboard_thumbnail(current_user="admin", dashboard_id=1, 
force=True)
+
+    assert result is None
+
+
+@_apply_patches
+def test_cache_dashboard_thumbnail_always_delegates_to_compute_and_cache(
+    mock_screenshot_cls,
+    mock_get_url_path,
+    mock_override_user,
+    mock_security_manager,
+    mock_get_executor,
+    mock_dashboard,
+    mock_thumbnail_cache,
+):
+    """Task always calls compute_and_cache; dedup lives inside 
compute_and_cache."""
+    from superset.tasks.thumbnails import cache_dashboard_thumbnail
+
+    mock_screenshot = _make_screenshot_mock()
+    mock_screenshot_cls.return_value = mock_screenshot
+    mock_get_executor.return_value = (None, "admin")
+    mock_security_manager.find_user.return_value = MagicMock()
+
+    with patch("superset.models.dashboard.Dashboard.get", 
return_value=mock_dashboard):
+        cache_dashboard_thumbnail(

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Dead code: unused variable</b></div>
   <div id="fix">
   
   In `superset/tasks/thumbnails.py` at line 97, the assignment to 
`resolved_cache_key` is never used in the subsequent `compute_and_cache` call. 
You may want to remove this unused variable or pass it instead of the original 
`cache_key` parameter.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1823a5</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to