librelist archives

« back to archive

Flask-SQLAlchemy Troubles

Flask-SQLAlchemy Troubles

From:
Anthony Ford
Date:
2012-04-14 @ 14:32
I'm having some issues with the Flask-SQLAlchemy package. I'm moving a
flask-based app
to a new server, where I have to use a MySQL server which is bound to a
unix socket only.

After searching a bit, I stumbled upon SQLAlchemy'sEngine Configuration
page which
specifies that arguments can be passed via the URI, and that I can pass the
unix socket
command to `create_engine` via the URI like so:

URI = "mysql+pymysql://user:pwd@localhost
/db?unix_socket=/var/mysql/mysql.sock"

However, it fails to be parsed by SQLAlchemy. However, if I pass the
arguments via the
`connect_args` argument in `create_engine`, it successfully creates a
connection.


Is there an existing way to pass a dictionary to connect_args in
Flask-SQLAlchemy? Or a
way to redefine the engine created by Flask-SQLAlchemy?


Thanks,
Anthony Ford,
KF5IBN,
Research Assistant,
Center for Advanced Radio Astronomy,
University of Texas at Brownsville
ford.anthonyj@gmail.com

Re: [flask] Flask-SQLAlchemy Troubles

From:
Armin Ronacher
Date:
2012-04-14 @ 17:56
Hi,

Are you sure this is supported by pymysql?


Regards,
Armin

Re: [flask] Flask-SQLAlchemy Troubles

From:
Anthony Ford
Date:
2012-04-14 @ 18:12
Yes. I'm able to create the engine and connect to the mysqld in the python
console via:

`sqlalchemy.create_engine("mysql+pymysql://", connect_args={'user':'USER',
'passwd':'PASS', 'db':'DATABASE', 'unix_socket':'/var/mysql/mysql.sock'} )`

and successfully connect and query.

I made a patch to flask-sqlalchemy that passes in connect_args and works
successfully on my server:


https://github.com/ajford/flask-sqlalchemy/commit/296e0a9c9db62ae5f3a7bc26b335af9503ba6072

Anthony Ford,
KF5IBN,
Research Assistant,
Center for Advanced Radio Astronomy,
University of Texas at Brownsville
ford.anthonyj@gmail.com



On Sat, Apr 14, 2012 at 12:56, Armin Ronacher
<armin.ronacher@active-4.com>wrote:

> Hi,
>
> Are you sure this is supported by pymysql?
>
>
> Regards,
> Armin
>