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


##########
superset/commands/streaming_export/base.py:
##########
@@ -192,23 +227,27 @@ def run(self) -> Callable[[], Generator[str, None, None]]:
         # to avoid DetachedInstanceError
         sql, database = self._get_sql_and_database()
         limit = self._get_row_limit()
+        # Capture g attributes for restoration in the new context
+        captured_g = self._captured_g
 
         def csv_generator() -> Generator[str, None, None]:
             """Generator that yields CSV data chunks."""
             with self._current_app.app_context():
-                try:
-                    yield from self._execute_query_and_stream(sql, database, 
limit)
-                except Exception as e:
-                    logger.error("Error in streaming CSV generator: %s", e)
-                    import traceback
-
-                    logger.error("Traceback: %s", traceback.format_exc())
-
-                    # Send error marker for frontend to detect
-                    error_marker = (
-                        "__STREAM_ERROR__:Export failed. "
-                        "Please try again in some time.\n"
-                    )
-                    yield error_marker
+                # Restore flask.g attributes (e.g., tenant info for 
multi-tenant setups)
+                with preserve_g_context(captured_g):
+                    try:
+                        yield from self._execute_query_and_stream(sql, 
database, limit)
+                    except Exception as e:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Blind exception catch too broad</b></div>
   <div id="fix">
   
   Replace the broad `Exception` catch with specific exception types (e.g., 
`DatabaseError`, `SQLAlchemyError`) to avoid catching unexpected errors.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
                       except (SQLAlchemyError, Exception) as e:
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #65a420</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