klen / klen/mixer

Sqlalchemy backend should create a transaction if it is going to call session.commit

Open
#115 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
953
Forks
91
PR merge metrics
No merged PRs in 30d

Description

See
https://docs.sqlalchemy.org/en/13/orm/session_transaction.html
http://alextechrants.blogspot.com/2013/08/unit-testing-sqlalchemy-apps.html

L312 of https://github.com/klen/mixer/blob/develop/mixer/backend/sqlalchemy.py will end the session's current transaction and commit them.

This will break things that rely on nested sessions, such as the example above which use nested transaction to encapsulate tests. It seems like a good argument not to use nested transactions that way, but I think you should also try to avoid interfering with user transactions if possible.

Ie. I think you should either drop the session.commit() line, and let users interact with sessions how they want, or call session.begin_nested() before session.add, so that the commit will not effect parent transactions.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in mixer/backend/sqlalchemy.py around line 312 and read the linked SQLAlchemy session transaction documentation and nested-session example. Reproduce how the current session.commit() affects a caller's nested transaction, then determine which transaction behavior preserves the user's session boundaries. Done means fixture creation no longer interferes with an existing parent transaction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.