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


##########
superset/common/query_context_processor.py:
##########
@@ -132,7 +138,56 @@ def get_df_payload(
                         )
                     )
 
-                query_result = self.get_query_result(query_obj)
+                # Create a persisted Query row for chart queries so we can 
expose a
+                # client_id and allow cancellation later. This mirrors SQL 
Lab's
+                # behavior; it is best-effort and only created if the 
datasource has
+                # an underlying database.
+                if (
+                    hasattr(self._qc_datasource, "database")
+                    and getattr(self._qc_datasource, "database", None) is not 
None
+                ):
+                    try:
+                        from uuid import uuid4
+
+                        from superset.models.sql_lab import Query as 
SqlLabQuery
+                        from superset.utils.core import get_user_id
+
+                        # Use client_id if provided by the client (e.g., 
frontend)
+                        provided_client_id = (
+                            self._query_context.cache_values.get("client_id")
+                            if isinstance(self._query_context.cache_values, 
dict)
+                            else None
+                        )
+
+                        client_id = provided_client_id or uuid4().hex[:11]
+
+                        # If a Query with this client_id already exists, reuse 
it.
+                        query_model = (
+                            db.session.query(SqlLabQuery)
+                            .filter_by(client_id=client_id)
+                            .one_or_none()
+                        )
+
+                        if not query_model:
+                            query_model = SqlLabQuery(
+                                client_id=client_id,
+                                database_id=self._qc_datasource.database.id,
+                                user_id=get_user_id(),
+                            )
+                            db.session.add(query_model)
+                            db.session.commit()
+
+                    except (
+                        Exception
+                    ):  # pragma: no cover - best-effort Query model creation
+                        db.session.rollback()
+                        logger.debug(
+                            "Could not create Query model for chart query",
+                            exc_info=True,
+                        )

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Avoid catching blind Exception</b></div>
   <div id="fix">
   
   Replace bare `except Exception` with more specific exception handling or at 
minimum log the exception type.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
                       except (
                           Exception
                       ) as exc:  # pragma: no cover - best-effort Query model 
creation
                           db.session.rollback()
                           logger.debug(
                               "Could not create Query model for chart query",
                               exc_info=True,
                               extra={"exception_type": type(exc).__name__},
                           )
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #782a1f</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