Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-21 Thread Venkata Siva Naga Tatikonda
Nevermind, I'm able to test this as well, thanks! On Friday, June 19, 2020 at 5:39:34 PM UTC-7, Venkata Siva Naga Tatikonda wrote: > > Hello Mike, > > Need another suggestion similar to this: > > Instead of fetching password from AWS SecretsManager every time, we want > to establish the

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-19 Thread Venkata Siva Naga Tatikonda
Hello Mike, Need another suggestion similar to this: Instead of fetching password from AWS SecretsManager every time, we want to establish the connection using the cached credentials and it that doesn't work then only we would make AWS API call for secrets. @event.listens_for(db,

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-19 Thread Mike Bayer
OK great, I was just throwing out assorted debugging techniques to help you find the problem On Fri, Jun 19, 2020, at 12:43 AM, Venkata Siva Naga Tatikonda wrote: > Thanks Mike, able to achieve the desired results. > > > On Thursday, June 18, 2020 at 12:36:15 PM UTC-7, Mike Bayer wrote: >>

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-18 Thread Venkata Siva Naga Tatikonda
Thanks Mike, able to achieve the desired results. On Thursday, June 18, 2020 at 12:36:15 PM UTC-7, Mike Bayer wrote: > > > > On Wed, Jun 17, 2020, at 8:59 PM, Venkata Siva Naga Tatikonda wrote: > > Hello Mike, > > I've embedded the following code within the get_session function where the >

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-18 Thread Mike Bayer
Additionally, enable echo_pool=True on your create_engine which will log when connections are being made. Put logging and/or print statements inside your event handler to ensure it's being invoked when it is expected. run some standalone tests with a short script first to make sure it does

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-18 Thread Mike Bayer
On Wed, Jun 17, 2020, at 8:59 PM, Venkata Siva Naga Tatikonda wrote: > Hello Mike, > > I've embedded the following code within the get_session function where the > get_engine function returns the engine object. However, I'm still seeing that > the rotated database credentials are not being

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Venkata Siva Naga Tatikonda
Hello Mike, latest update, I've tried to keep hook separately out of session but still not working when database credentials changed def get_engine(args): # our code to create engine return engine def get_session(args): db = get_engine(args) # create scoped_session

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Mike Bayer
On Wed, Jun 17, 2020, at 5:17 PM, Venkata Siva Naga Tatikonda wrote: > Hello Mike, > > Thanks for your insight and response. > > Just want to let you know that, we are using scoped_session with a > session_factory object to db connections. Does this approach still suitable > for connections

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Venkata Siva Naga Tatikonda
Hello Mike, I've embedded the following code within the get_session function where the get_engine function returns the engine object. However, I'm still seeing that the rotated database credentials are not being used when creating new connections def get_engine(args): # our code to

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Venkata Siva Naga Tatikonda
Basically, within get_session function we call get_engine method and if an engine already exists it skips the creation and uses it. If an engine doesn't exist then it will create one and uses it. After that, we create a sessionmaker object by binding that engine & some other arguments and then

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Venkata Siva Naga Tatikonda
Hello Mike, Thanks for your insight and response. Just want to let you know that, we are using scoped_session with a session_factory object to db connections. Does this approach still suitable for connections using session ? Also, we have custom module where we have separate functions for

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Mike Bayer
We're going to need an FAQ entry for this since this now comes up regularly for everyone using AWS. There are two methods to manipulate the parameters sent to connect that are independent of the URL. They are both described now at

[sqlalchemy] Changing database credentials after engine creation

2020-06-16 Thread Venkata Siva Naga Tatikonda
Hello Everyone, Need some suggestion/insight on some use case we have: We have python django web application which uses sqlalchemy v1.3.13 (mysqldb) to communicate with AWS Aurora (RDS). This application uses AWS Secrets Manager for managing database credentials and utilizing sqlalchemy (w/