Compare commits

...

2 Commits

Author SHA1 Message Date
Elizabeth Thompson
c563e9414f refactor(dashboard): use logger.exception for cleaner error logging
Replace logger.error with exc_info=True with logger.exception() for more concise and idiomatic exception logging in thumbnail retrieval.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-24 16:44:13 -07:00
Elizabeth Thompson
b7ee772034 fix(dashboard): handle invalid thumbnail BytesIO objects gracefully
Fixes an AttributeError that occurred when the thumbnail endpoint tried to serve
an invalid or corrupted BytesIO object. The error manifested as:
`AttributeError: 'NoneType' object has no attribute 'read'`

This happened when the WSGI layer attempted to read from a FileWrapper that was
passed a None or invalid BytesIO object.

Changes:
- Add validation to check BytesIO contains actual data (nbytes > 0)
- Reset file position with seek(0) before passing to FileWrapper
- Add comprehensive exception handling with detailed error logging
- Return proper 404 responses for all invalid thumbnail states

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 15:22:07 -07:00

View File

@@ -1342,10 +1342,31 @@ class DashboardRestApi(BaseSupersetModelRestApi):
self.incr_stats("from_cache", self.thumbnail.__name__)
try:
image = cache_payload.get_image()
# Validate the BytesIO object is properly initialized
if not image or not hasattr(image, "read"):
logger.warning(
"Thumbnail image object is invalid for dashboard %s",
str(dashboard.id),
)
return self.response_404()
# Additional validation: ensure the BytesIO has content
if image.getbuffer().nbytes == 0:
logger.warning(
"Thumbnail image is empty for dashboard %s",
str(dashboard.id),
)
return self.response_404()
# Reset position to ensure reading from start
image.seek(0)
except ScreenshotImageNotAvailableException:
return self.response_404()
except Exception as ex: # pylint: disable=broad-except
logger.exception(
"Error retrieving thumbnail for dashboard %s: %s",
str(dashboard.id),
str(ex),
)
return self.response_404()
return Response(
FileWrapper(image),
mimetype="image/png",