Re: [sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Jonathan Vanasco
On Thursday, March 26, 2020 at 2:53:08 PM UTC-4, Mike Bayer wrote: > > is the issue that your follower database is only updating > asynchronously? I would likely organize the application to simply use two > different Session objects, one for master one for follower. Trying to do > it on a

Re: [sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Mike Bayer
On Thu, Mar 26, 2020, at 2:45 PM, Colton Allen wrote: > Aside from disabling expire_on_commit, any thoughts on how I can prevent this > error? I guess I just need a method to force the attribute refresh to use the > master database. I'm just not sure where I should put that. Thoughts? is the i

Re: [sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Colton Allen
Aside from disabling expire_on_commit, any thoughts on how I can prevent this error? I guess I just need a method to force the attribute refresh to use the master database. I'm just not sure where I should put that. Thoughts? I think one of my previous comments got lost because of formatting

Re: [sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Mike Bayer
On Thu, Mar 26, 2020, at 2:18 PM, Colton Allen wrote: > > You can adjust `expire_on_commit` if you're only doing short-term read-only > > actions. > > Can you expand on this? Or link to docs/blog so I can do some research. > Google hasn't helped me so far. Why would I want to expire after ever

[sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Jonathan Vanasco
By default, SqlAlchemy has `expire_on_commit=True`. I'm going to poorly restate most of what Mike Bayer has told me in the past: the rationale behind this- an active Session is supposed to mirror the current state in the database; within a transaction we know the object values are equal to th

[sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Colton Allen
> You can adjust `expire_on_commit` if you're only doing short-term read-only actions. Can you expand on this? Or link to docs/blog so I can do some research. Google hasn't helped me so far. Why would I want to expire after every commit? --- I agree with your assessment. I think its becau

[sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Jonathan Vanasco
My first guess is two things are going on: 1. This is a behavior of `expire_on_commit` on the session. Once you commit on the Primary database, the object is stale. https://docs.sqlalchemy.org/en/13/orm/session_api.html 2. The session is then trying to read off a Secondary database, but the

[sqlalchemy] ObjectDeletedError in master/slave configuration

2020-03-26 Thread Colton Allen
Hi, I'm using a custom session class to route requests to different database engines based on the type of action being performed. Master for writes; slave for reads. It looks my attributes on my models expire immediately after creation. Anyway to prevent this? Or should I not worry about p

Re: [sqlalchemy] Cleaning metadata

2020-03-26 Thread Javier Collado Jiménez
Thank you Mike! I'm going to try this different approach. El miércoles, 25 de marzo de 2020, 13:30:47 (UTC+1), Mike Bayer escribió: > > > > On Wed, Mar 25, 2020, at 6:27 AM, Javier Collado Jiménez wrote: > > Hello, > I'm having a problem trying to cleanup sqlalchemy objects. My application > has