michael-s-molina commented on code in PR #33300:
URL: https://github.com/apache/superset/pull/33300#discussion_r2069319039


##########
superset/utils/metadata.py:
##########
@@ -0,0 +1,9 @@
+from superset import db
+
+class SuspendSession:
+    def __enter__(self):
+        self.session_objects = db.session.identity_map.values()
+        db.session.remove()
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        for obj in self.session_objects:
+            db.session.add(obj)

Review Comment:
   I agree with @villebro. Detaching/reattaching objects bring session sync 
problems. For example, you would need to use `merge` instead of `add` when 
reattaching given that the database might have changed while you wait for the 
analytical query to complete. `merge` would sync with the actual state of the 
database but also fire additional queries. Another thing is that `flush` would 
also need to be invoked before `remove` to avoid losing changes. In other 
words, there might be simpler alternatives.



-- 
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