pauldex / sqlalchemy-firebird

A Firebird dialect for SQLAlchemy using the firebird-driver and/or fdb python Firebird driver
MIT License
23 stars 15 forks source link

SqlAlchemy 2.0. multiple sessions #45

Closed tomasbrchan closed 10 months ago

tomasbrchan commented 1 year ago

Hi, I have a problem with session.commit() when I connect from multiple sources (in my case processes). I use docker firebird https://hub.docker.com/r/jacobalberty/firebird, but it should not be a problem (I hope).

I use this code to add new data row to table:

with Session(engine) as session:
    try:
        session.add(Model)
    except:
        session.rollback()
        raise
    else:
        session.commit()

If I use only one process no problem. When I start more processes, they probably create more session the same time and commit the same time and that's the problem.

I have no idea it this is problem of firebird, fdb or sqlalchemy-firebird.

Do you have any suggestion? Do I use it wrong way?

Thanks a lot. Tomas

pauldex commented 1 year ago

I haven't had any problems using the docker firebird you mentioned. You could try using the embedded server (no installation needed) to determine if the server is the problem.

Just some thoughts. Are you adding different data rows in each process? Do all of the processes fail when using multiple processes? Is there a way to share one session among all the processes?

fdcastel commented 11 months ago

Without a reproducible case to work on, I suggest we close this one.

pauldex commented 10 months ago

Agreed. Multiple processes accessing the database should not be an issue as long as they are using the same server.