bito-code-review[bot] commented on PR #44546:
URL: https://github.com/apache/superset/pull/44546#issuecomment-5787601186
<!-- Bito Reply -->
The flagged issue is correct. In the current implementation, if a DAO lookup
or lazy datasource loading (such as `ChartDAO.find_by_id` or RLS lookups)
raises an exception before the `try` block, it can indeed cause the entire
chart-data request to fail, even if the annotation cache-key itself is not the
primary cause of the failure.
To resolve this, you should wrap the annotation-related lookups and
cache-key generation in a `try...except` block to ensure that failures in
annotation processing do not propagate and abort the entire request. The
implementation should catch potential exceptions (like `RuntimeError` or other
database-related errors) and handle them gracefully, for example by failing
closed (e.g., setting `annotation_data` to an empty dictionary or a safe
fallback state) rather than allowing the exception to bubble up.
I have checked the PR comments, and there are no other comments to address.
Would you like me to implement this fix for you?
**superset/common/query_context_processor.py**
```
annotation_data: dict[str, Any] = {}
if query_obj and annotation_key and cache.status !=
QueryStatus.FAILED:
try:
annotation_data = self._get_annotation_data_cached(
query_obj=query_obj,
cache_key=annotation_key,
force_query=force_query,
force_cached=force_cached,
timeout=self.get_cache_timeout(),
datasource_uid=self._qc_datasource.uid,
)
except (QueryObjectValidationError, Exception) as ex:
# Log the error and fail closed for annotations
logger.exception("Failed to load annotation data")
cache.error_message = str(ex)
cache.status = QueryStatus.FAILED
```
--
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]