Antonio-RiveroMartnez commented on code in PR #36222:
URL: https://github.com/apache/superset/pull/36222#discussion_r2549568319
##########
superset/commands/sql_lab/results.py:
##########
@@ -59,40 +59,65 @@ def validate(self) -> None:
)
)
- read_from_results_backend_start = now_as_float()
- self._blob = results_backend.get(self._key)
- app.config["STATS_LOGGER"].timing(
- "sqllab.query.results_backend_read",
- now_as_float() - read_from_results_backend_start,
- )
+ stats_logger = app.config["STATS_LOGGER"]
- if not self._blob:
+ # Check if query exists in database first (fast, avoids unnecessary S3
call)
+ self._query = (
+
db.session.query(Query).filter_by(results_key=self._key).one_or_none()
+ )
+ if self._query is None:
+ logger.error(
+ "404 Error - Query not found in database for key: %s",
+ self._key,
+ )
+ stats_logger.incr("sqllab.results_backend.404_query_not_found")
raise SupersetErrorException(
SupersetError(
message=__(
- "Data could not be retrieved from the results backend.
You "
- "need to re-run the original query."
+ "The query associated with these results could not be
found. "
+ "You need to re-run the original query."
),
error_type=SupersetErrorType.RESULTS_BACKEND_ERROR,
level=ErrorLevel.ERROR,
),
- status=410,
+ status=404,
)
- self._query = (
-
db.session.query(Query).filter_by(results_key=self._key).one_or_none()
+ # Now fetch results from backend (query exists, so this is a valid
request)
+ read_from_results_backend_start = now_as_float()
+ self._blob = results_backend.get(self._key)
+ stats_logger.timing(
+ "sqllab.query.results_backend_read",
+ now_as_float() - read_from_results_backend_start,
)
- if self._query is None:
+
+ if not self._blob:
+ # Query exists in DB but results not in S3 - enhanced diagnostics
+ query_age_seconds = now_as_float() - (
+ self._query.end_time if self._query.end_time else
now_as_float()
+ )
+ logger.error(
Review Comment:
same
##########
superset/commands/sql_lab/results.py:
##########
@@ -59,40 +59,65 @@ def validate(self) -> None:
)
)
- read_from_results_backend_start = now_as_float()
- self._blob = results_backend.get(self._key)
- app.config["STATS_LOGGER"].timing(
- "sqllab.query.results_backend_read",
- now_as_float() - read_from_results_backend_start,
- )
+ stats_logger = app.config["STATS_LOGGER"]
- if not self._blob:
+ # Check if query exists in database first (fast, avoids unnecessary S3
call)
+ self._query = (
+
db.session.query(Query).filter_by(results_key=self._key).one_or_none()
+ )
+ if self._query is None:
+ logger.error(
Review Comment:
should we log as warning instead since you're logging the error in
`superset/sql_lab.py` -> `...if not write_success:` ?
--
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]