Session within a session

15 views
Skip to first unread message

Jason Hoppes

unread,
Apr 20, 2022, 11:28:44 AM4/20/22
to sqlalchemy
I have an object that adds a user. I have another Object that gets cipher information for that user's password. Each one having their own session. Could I call the object that gets the cipher with a separate session with the session that I add the user? Effectively it does a lookup using an inner session.

Thanks in advance for your help.

- Jason

Mike Bayer

unread,
Apr 20, 2022, 8:45:39 PM4/20/22
to noreply-spamdigest via sqlalchemy
you can work with multiple sessions and their objects simultaneously, with the provision that you don't add() an object from one session directly into the other one, without detaching it from the original session first.  to transfer the state of an object from one session to another without detaching it, use the session.merge() method.

more important is that when you work with these sessions, the sessions are not being simultaneously accessed by other concurrent tasks such as those in other threads, greenlets or async coroutines.  if the two sessions are local to the current task/thread/whatever, just keep track of which objects are from which and it will be fine.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Jason Hoppes

unread,
Apr 29, 2022, 12:17:13 PM4/29/22
to sqlalchemy
Sorry I got diverted on another project. I will try this later and let you know. Thanks for your help.

- Jason
Reply all
Reply to author
Forward
0 new messages