Skip to content

Use autoflush=False for SQLAlchemy sessions #3552

@r4victor

Description

@r4victor

By default, SQLAlchemy sessions work in autoflush=True mode. In this mode, all pending changes to the session are committed on any session.execute, so even selects may trigger write operations. It can be a big problem on SQLite leading to long write transactions and "database is locked" errors.

Switch to autoflush=False. This is a huge change to ORM semantics but luckily for us, the dstack code does not rely on autoflush much. There are few places that need to be fixed:

Potentially:

  • generate_*_name functions like this but only if used to create multiple objects in a session.

On a related note, ensure there are no long write transactions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions