Skip to content

Commit

Permalink
Invert location of more explanatory test transaction comment
Browse files Browse the repository at this point in the history
The sync and async `test_tx` fixtures have been inverted as to their
position in the file, so "see above" didn't make sense anymore. Here,
move the longer, more explanatory comment up to async `test_tx` since
it's not nearer to the top of the file.
  • Loading branch information
brandur committed Jul 7, 2024
1 parent e90ec18 commit f4d1361
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/driver/riversqlalchemy/sqlalchemy_driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ async def test_tx(
async with engine_async.connect() as conn_tx:
# Force SQLAlchemy to open a transaction.
#
# See explanatory comment in `test_tx()` above.
# SQLAlchemy seems to be designed to operate as surprisingly as
# possible. Invoking `begin()` doesn't actually start a transaction.
# Instead, it only does so lazily when a command is first issued. This
# can be a big problem for our internal code, because when it wants to
# start a transaction of its own to do say, a uniqueness check, unless
# another SQL command has already executed it'll accidentally start a
# top-level transaction instead of one in a test transaction that'll be
# rolled back, and cause our tests to commit test jobs. So to work
# around that, we make sure to fire an initial command, thereby forcing
# a transaction to begin. Absolutely terrible design.
await conn_tx.execute(sqlalchemy.text("SELECT 1"))

yield conn_tx
Expand Down Expand Up @@ -221,16 +230,7 @@ def test_tx(engine: sqlalchemy.Engine) -> Iterator[sqlalchemy.Connection]:
with engine.connect() as conn_tx:
# Force SQLAlchemy to open a transaction.
#
# SQLAlchemy seems to be designed to operate as surprisingly as
# possible. Invoking `begin()` doesn't actually start a transaction.
# Instead, it only does so lazily when a command is first issued. This
# can be a big problem for our internal code, because when it wants to
# start a transaction of its own to do say, a uniqueness check, unless
# another SQL command has already executed it'll accidentally start a
# top-level transaction instead of one in a test transaction that'll be
# rolled back, and cause our tests to commit test jobs. So to work
# around that, we make sure to fire an initial command, thereby forcing
# a transaction to begin. Absolutely terrible design.
# See explanatory comment in `test_tx()` above.
conn_tx.execute(sqlalchemy.text("SELECT 1"))

yield conn_tx
Expand Down

0 comments on commit f4d1361

Please sign in to comment.