Files
galaxy/test
John Davis 377f783e20 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.
2023-12-12 14:38:46 -05:00
..
2023-01-26 13:45:42 -05:00