Always-prog commented on code in PR #33300:
URL: https://github.com/apache/superset/pull/33300#discussion_r2069526991


##########
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:
   @michael-s-molina I'll try flush and merge, thank you.
   The reason I manually add objects is to fix this problem
   
![image](https://github.com/user-attachments/assets/f9791622-9906-480c-a93c-e4b1a45c6cab)
   
   Error raises because the relationships in loaded models, such as Sql a 
Table, Column, and SqlaMetric, with lazy=True (the default), are unloaded from 
memory after the session.remove() method is called. Accessing these objects 
after the session is closed will raise a DetachedInstanceError.
   
   
   @villebro I was getting unexpected error using session.close(), but don't 
remember why. I'll try to use it again later.



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