I'm using SQLAlchemy with Flask as shown here: http://flask.pocoo.org/docs/patterns/sqlalchemy/
I have a Selenium test suite that first runs with Firefox and then with Chrome.
Before the start of tests on each browsers, tables in the test database (PostgreSQL) are dropped and created.
It runs perfectly for the first browsers, but for the second browser the SQL create / drop attempt just freezes and no errors are shown.
I believe this is because of open SQLAlchemy sessions, is that correct?
Why SQLAlchemy to Connect PostgreSQL to a Flask Application? SQLAlchemy is an ORM-Objects Relational Mapper written in Python. It gives away around to interact with the Databases without using SQL statements. It provides an extra layer on top of SQL which allows us to use Databases and Tables just like Python Class Objects.
What is PostgreSQL? According to its Wikipedia page, "PostgreSQL, also known as Postgres, is a free and open-source relational database management system (RDBMS) emphasizing extensibility and SQL compliance" - Wikipedia
The SQLALCHEMY_DATABASE_URI expects a very particularly formatted string, which you can see below. We tell it what database and communication-library to use, the username, password, url and even database to connect to.
To install PostgreSQL, visit the link here. Once PostgreSQL is installed, open the SQL shell and set up your DB connection Username and password. Run the below command to open shell in Terminal:
I believe this is because of open SQLAlchemy sessions, is that correct?
That's most likely the case. To confirm it, connect to the postgres
database and run SELECT * FROM pg_stat_activity
;
I'm not sure how you handle the DB creation/dropping but you may want to call dispose()
and possibly recreate()
on the SQLAlchemy connection pool, after making sure that any checked out connection has been returned (for example, with session.close()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With