You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "TacoBel42 (via GitHub)" <gi...@apache.org> on 2024/07/05 15:33:47 UTC

Re: [PR] Celery uses separate db engine with NullPool. [superset]

TacoBel42 commented on code in PR #1492:
URL: https://github.com/apache/superset/pull/1492#discussion_r1666938613


##########
caravel/sql_lab.py:
##########
@@ -46,10 +51,17 @@ def create_table_as(sql, table_name, schema=None, override=False):
     return exec_sql.format(**locals())
 
 
-@celery_app.task
-def get_sql_results(query_id, return_results=True, store_results=False):
+@celery_app.task(bind=True)
+def get_sql_results(self, query_id, return_results=True, store_results=False):
     """Executes the sql query returns the results."""
-    session = db.session()
+    if not self.request.called_directly:
+        engine = sqlalchemy.create_engine(
+            app.config.get('SQLALCHEMY_DATABASE_URI'), poolclass=NullPool)
+        session_class = sessionmaker()
+        session_class.configure(bind=engine)
+        session = session_class()
+    else:
+        session = db.session()
     session.commit()  # HACK

Review Comment:
   @mistercrunch why? what does HACK do?



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org