Skip to content

Commit

Permalink
raising selenium exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fisjac committed Jan 16, 2025
1 parent 2b7f3ad commit 22f419d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ def thumbnail(self, pk: int, digest: str, **kwargs: Any) -> WerkzeugResponse:
cache_dashboard_thumbnail.delay(
current_user=current_user,
dashboard_id=dashboard.id,
force=True,
force=False,
)
return self.response(
202,
Expand Down
2 changes: 1 addition & 1 deletion superset/utils/screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def compute_and_cache( # pylint: disable=too-many-arguments
with event_logger.log_context(f"screenshot.cache.{self.thumbnail_type}"):
cache_payload.update(image)
self.cache.set(cache_key, cache_payload)
logger.info("Updated thumbnail cache")
logger.info("Updated thumbnail cache; Status: %s", cache_payload.get_status())
return

@classmethod
Expand Down
9 changes: 7 additions & 2 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def find_unexpected_errors(driver: WebDriver) -> list[str]:

return error_messages

def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | None:
def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | None: # noqa: C901
driver = self.auth(user)
driver.set_window_size(*self._window)
driver.get(url)
Expand Down Expand Up @@ -379,7 +379,7 @@ def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | Non
)
)
except TimeoutException:
logger.info("caught Timeout Exception")
logger.info("Timeout Exception caught")
# Fallback to allow a screenshot of an empty dashboard
try:
WebDriverWait(driver, 0).until(
Expand Down Expand Up @@ -430,6 +430,9 @@ def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | Non
)

img = element.screenshot_as_png
except Exception as ex:
logger.warning("exception in webdriver", exc_info=ex)
raise
except TimeoutException:
# raise again for the finally block, but handled above
raise
Expand All @@ -438,10 +441,12 @@ def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | Non
"Selenium got a stale element while requesting url %s",
url,
)
raise
except WebDriverException:
logger.exception(
"Encountered an unexpected error when requesting url %s", url
)
raise
finally:
self.destroy(driver, current_app.config["SCREENSHOT_SELENIUM_RETRIES"])
return img

0 comments on commit 22f419d

Please sign in to comment.