Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit instead of flushing in unit test
Rationale: We use an in-memory sqlite database for quota tests. With SA 2.0 (or with the `future` flag enabled on the engine), the following conflict happens: (this is a simplified model) foo = Foo() session.add(foo) session.flush() engine = session.get_bind() with engine.connect() as conn: conn.execute(some-sql) foo.bar = "new value" session.commit() # BOOM!!!! sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'galaxy_user' expected to update 1 row(s); 0 were matched. Reason for BOOM: With an in-memory database, the underlying dbapi_connection object is the same for the session and the engine.connect(). Here's what happens: line 10: foo is flushed to the db tmp buffer line 14: conn is closed on exit from context manager, which issues a rollback, which rolls back whatever is in the tmp buffer - so foo is never inserted. line 16: foo is updated line 17: error happens: the session thinks it's updating foo's record in the db, but that record does not exist therefore, "0 rows matched". Solution: commit instead of flushing - then foo is inserted.
- Loading branch information