Skip to content

fix(#121): handle join_txn_mode for version_session - #122

Merged
indiVar0508 merged 1 commit into
corridor:masterfrom
ashish16052:master
Jan 9, 2024
Merged

indiVar0508 merged 1 commit into
corridor:masterfrom
ashish16052:master

Conversation

@ashish16052

Copy link
Copy Markdown
Collaborator
  • SQLA 2.0 introduced new session param called join_transaction_mode which changes the behaviour of how existing transactions are handled

  • When using a Connection with an existing SAVEPOINT: SQLA-1.4: the Session would propagate both commit() and rollback() calls to the underlying transaction. SQLA-2.0: use join_transaction_mode=control_fully to replicate the same behaviour.

  • When using a Connection without an existing SAVEPOINT: SQLA-1.4: the Session would propagate only rollback() calls to the underlying transaction. SQLA-2.0: use join_transaction_mode=rollback_only to replicate the same behaviour.

  • use rollback_only mode while creation of version_session, as it is using an existing connection, and we are never doing a commit() on it.

Documentation: join_transaction_mode

@coveralls

coveralls commented Jan 4, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 7457526996

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 97.432%

Totals Coverage Status
Change from base Build 7457305400: 0.03%
Covered Lines: 5130
Relevant Lines: 5185

💛 - Coveralls

@ashish16052 ashish16052 changed the title fix(#121): handle join_trnx_mode for version_session fix(#121): handle join_txn_mode for version_session Jan 4, 2024
Comment thread sqlalchemy_history/unit_of_work.py Outdated
self.reset()

def create_version_session(self, session):
return sa.orm.session.Session(bind=session.connection(), join_transaction_mode="rollback_only")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also have to handle sqla 1.4 here aswell.

current CI workflow seems to have a bug, where sqla-1.4 is not getting installed in poetry's env,

can you also fix that?, if the fix breaks other items in CI we can create a seperate issue for it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried fixing this by replacing:
pip install 'sqlalchemy${{ matrix.sqla }}'
with
poetry add "sqlalchemy${{ matrix.sqla }}"

it is breaking other tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased branch with ci fix done in #124


if not self.version_session:
self.version_session = sa.orm.session.Session(bind=session.connection())
self.version_session = self.create_version_session(session)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add testcase for this behaviour.

- SQLA 2.0 introduced new session param called `join_transaction_mode`
  which changes the behaviour of how existing transactions are handled

- When using a Connection with an existing SAVEPOINT:
  `SQLA-1.4`: the Session would propagate both commit() and rollback()
  calls to the underlying transaction.
  `SQLA-2.0`: use join_transaction_mode=control_fully to replicate the
  same behaviour.

- When using a Connection without an existing SAVEPOINT:
  `SQLA-1.4`: the Session would propagate only rollback() calls to the
  underlying transaction.
  `SQLA-2.0`: use join_transaction_mode=rollback_only to replicate the
  same behaviour.

- use `rollback_only` mode while creation of version_session, as it is
  using an existing connection, and we are never doing a commit() on it.

@indiVar0508 indiVar0508 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a minor comment

self.reset()

def create_version_session(self, session):
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test seems to be working with rebased code,
can you add small note saying what happened here so if someone comes cold to this code and has no gitlens is not confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants