engine_from_config and connect_args

324 views
Skip to first unread message

Boris Sabatier

unread,
Dec 30, 2014, 1:13:05 PM12/30/14
to sqlal...@googlegroups.com
Hi,

I need to pass connect_args={'isolation_level':None} when I create my engine.
With create_engine, it's work well.

But I would like to use engine_from_config instead of create_engine.

This is what I tried and the errors :

# ini file :
sqlalchemy.connect_args = {'isolation_level':None}
# Error
cparams.update(pop_kwarg('connect_args', {}))
ValueError: dictionary update sequence element #0 has length 1; 2 is required

# ini file
sqlalchemy.connect_args.isolation_level = None
# Error
TypeError: Invalid argument(s) 'connect_args.isolation_level' sent to create_engine()

Did someone has ever used connect_args in the ini file ?

Thanks for your help.

Boris


Michael Bayer

unread,
Dec 30, 2014, 1:42:37 PM12/30/14
to sqlal...@googlegroups.com


Boris Sabatier <sabatie...@gmail.com> wrote:

Hi,

I need to pass connect_args={'isolation_level':None} when I create my engine.


“None” is the default that’s used if isolation_level is not passed, and means to do nothing.  So just don’t pass it, there’s no need to pass “None”.


With create_engine, it's work well.

But I would like to use engine_from_config instead of create_engine.

This is what I tried and the errors :

# ini file :
sqlalchemy.connect_args = {'isolation_level':None}

well if this were to be available in an .ini file, that’s not Python code in an .ini file, it would have to be interpreted, such as:

sqlalchemy.connect_args = none

there’s a system by which these values are interpreted on a case-by-case basis that’s stated in each dialect class, if the type is something other than string.    But this parameter isn’t part of that, since it’s just a string type, and there’s no “None” handling.   You’d just omit the argument to use the default value.

Boris SABATIER

unread,
Dec 30, 2014, 2:10:09 PM12/30/14
to sqlal...@googlegroups.com
@Michael:
Are you sure the default value of isolation_level is None ?

Because when I didn't set to None, I can't use nested session with
sqlite and when I set it to None it's works.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/ZVhiJa7QZOQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+...@googlegroups.com.
> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

Michael Bayer

unread,
Dec 30, 2014, 3:05:59 PM12/30/14
to sqlal...@googlegroups.com


Michael Bayer <mik...@zzzcomputing.com> wrote:

>>
>> # ini file :
>> sqlalchemy.connect_args = {'isolation_level':None}
>
> well if this were to be available in an .ini file, that’s not Python code in an .ini file, it would have to be interpreted, such as:
>
> sqlalchemy.connect_args = none


for those reading, let me correct this, connect_args aren’t interpreted by engine_from_config, these are in the URL query string, so the above example is wrong in that way as well. the theoretical setting for this would be:

create_engine(“sqlite:///file.db?isolation_level=none”)

but again we don’t interpret “none” there either.

Michael Bayer

unread,
Dec 30, 2014, 3:12:34 PM12/30/14
to sqlal...@googlegroups.com


Boris SABATIER <sabatie...@gmail.com> wrote:

> @Michael:
> Are you sure the default value of isolation_level is None ?

OK what I forgot to clarify in my other email is that you’re working with
“connect_args” here, which with engine_from_config would not be a separate
.ini value in any case; things that go into create_engine()->connect_args
are supposed to be in the query string. So the isolation_level you’re
talking about here isn’t SQLAlchemy’s version of this, it’s the one that’s
specific to the pysqlite DBAPI.

However, none of that matters, because you’re trying to use SAVEPOINT and
you definitely don’t just want to turn on pysqlite’s autocommit and do
nothing else.

Your use case here is specifically addressed here:

http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable

You will need to implement the events given there in order to use SAVEPOINT
transactions, which does include the “isolation_level=None” but also
critically re-implements the fact that you need to emit BEGIN at transaction
start.
> 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.

Boris SABATIER

unread,
Dec 30, 2014, 3:48:55 PM12/30/14
to sqlal...@googlegroups.com
Thanks Michael for the explanation.

The solution you link solve work but it doesn't satisfy me.
I use sqlite in developement and postgre in production. That's why I'm
looking for a "configuration's solution".

If you think it's isn't possible ti work, I will use postgre in each
environement.

Michael Bayer

unread,
Dec 30, 2014, 7:07:33 PM12/30/14
to sqlal...@googlegroups.com


Boris SABATIER <sabatie...@gmail.com> wrote:

> Thanks Michael for the explanation.
>
> The solution you link solve work but it doesn't satisfy me.
> I use sqlite in developement and postgre in production. That's why I'm
> looking for a "configuration's solution".
>
> If you think it's isn't possible ti work, I will use postgre in each
> environement.


just check the engine name:

if engine.dialect.name == ‘sqlite’:
# set up events

Boris SABATIER

unread,
Jan 2, 2015, 10:42:37 AM1/2/15
to sqlal...@googlegroups.com
Thanks Michael,

Even if it a "code side" solution, I think I will do it.

Michael Bayer

unread,
Jan 2, 2015, 3:20:12 PM1/2/15
to sqlal...@googlegroups.com
vote on getting the actual pysqlite bug fixed, this is just a workaround for their bug!

http://bugs.python.org/issue9924
Reply all
Reply to author
Forward
0 new messages