Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion based/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
raise ValueError("Invalid database URL")
schema = url_parts[0]

if force_rollback or (schema == "sqlite" and use_lock):
if use_lock and (force_rollback or schema == "sqlite"):
self._lock = Lock()

if schema == "sqlite":
Expand Down
21 changes: 21 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ async def test_database_force_rollback(
assert movie is None


async def test_database_force_rollback_with_lock(
table: sqlalchemy.Table,
database_url: str,
gen_movie: typing.Callable[[], typing.Tuple[str, int]],
):
title, year = gen_movie()

async with based.Database(
database_url, force_rollback=True, use_lock=True,
) as database:
async with database.session() as session:
query = table.insert().values(title=title, year=year)
await session.execute(query)

async with based.Database(database_url, force_rollback=True) as database:
async with database.session() as session:
query = table.select().where(table.c.title == title)
movie = await session.fetch_one(query)
assert movie is None


async def test_database_no_force_rollback(
table: sqlalchemy.Table,
database_url: str,
Expand Down