On 03/03/2017 12:08 PM, Евгений Рымарев wrote:
Hello everyone!
I have Flask app with using flask_sqlalchemy:

|
fromflask importFlask
fromflask_sqlalchemy importSQLAlchemy
app =Flask(__name__)
app.config.from_pyfile(filename='settings.py',silent=True)
db =SQLAlchemy(app=app)
|

I want connect to same database from daemon. In daemon i just import db
and use db.engine.execute for SQLAlchemy queries.
But when daemon starts main app can't connect to database.
In log i see that:
|
fdb.fbcore.DatabaseError:('Error while connecting to database:\n-
SQLCODE: -902\n- I/O error during "lock" operation for file
"main.fdb"\n- Database already opened with engine instance, incompatible
with current',-902,335544344)
|

I trying use isolation level:
|
fromfdb.fbcore importISOLATION_LEVEL_READ_COMMITED_LEGACY
classTPBAlchemy(SQLAlchemy):
    defapply_driver_hacks(self,app_,info,options):
        if'isolation_level'notinoptions:
            options['isolation_level']=ISOLATION_LEVEL_READ_COMMITED_LEGACY
        returnsuper(TPBAlchemy,self).apply_driver_hacks(app_,info,options)

So the Firebird dialects in SQLAlchemy have no "isolation level" support. But also, the isolation level feature in SQLAlchemy dialects set this value *after* the connection is made. The error you are getting indicates that you aren't connecting in the first place; so hopefully this is resolved by setting a certain isolation level on all connections.

In any case, to call firebird-specific APIs like isolation levels when you connect, use the pool connect event:

http://docs.sqlalchemy.org/en/latest/core/events.html#sqlalchemy.events.PoolEvents.connect


so on your Engine (I'm not sure how to do this with Flask, wherever they do create_engine or you can do it on the Engine class globally)


engine = create_engine("firebird+fdb://...")

@event.listens_for(engine, 'connect')
def receive_connect(dbapi_connection, connection_record):
    dbapi_connection.call_special_firebird_method(
             ISOLATION_LEVEL_READ_COMMITTED_LEGACY)


above you'd replace "call_special_firebird_method" with whatever you need to make this setting on the DBAPI connection.





|

And replace this:
|
db =SQLAlchemy()
|

To:
|
db =TPBAlchemy()
|

But this only make another error:
|
TypeError:Invalidargument(s)'isolation_level'sent to
create_engine(),usingconfiguration
FBDialect_fdb/QueuePool/Engine. Pleasecheck that the keyword arguments
are appropriate forthiscombination of components.
|

I would appreciate the full example to address my issue.
Thanks!

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
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+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 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+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to