Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add transaction isolation level #878

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jonathanblade
Copy link
Contributor

@jonathanblade jonathanblade commented Jan 23, 2024

Change Summary

Add support for interactive transactions with an isolation level.

Closes #463.

Checklist

  • Unit tests for the changes exist
  • Tests pass without significant drop in coverage
  • Documentation reflects changes where applicable
  • Test snapshots have been updated if applicable

Agreement

By submitting this pull request, I confirm that you can use, modify, copy and redistribute this contribution, under the terms of your choice.

@jonathanblade jonathanblade force-pushed the main branch 16 times, most recently from 7c96c66 to 875bb3d Compare January 24, 2024 06:22
@RobertCraigie RobertCraigie force-pushed the main branch 2 times, most recently from 41b8671 to d373351 Compare January 26, 2024 19:03
@jonathanblade jonathanblade force-pushed the main branch 7 times, most recently from e3f59f6 to 18b364c Compare January 31, 2024 08:14
Comment on lines 255 to 280
# TODO: remove after issue will be resolved
@pytest.mark.skipif(CURRENT_DATABASE in ['mysql', 'mariadb'], reason='https://github.com/prisma/prisma/issues/22890')
async def test_isolation_level(
client: Prisma, raw_queries: RawQueries, input_level: prisma.TransactionIsolationLevel, expected_level: str
) -> None:
"""A transaction isolation level is set correctly"""
async with client.tx(isolation_level=input_level) as tx:
results = await tx.query_raw(raw_queries.select_tx_isolation)

assert len(results) == 1

row = results[0]
assert any(row)

level = next(iter(row.values()))
# The result can depends on the database, so we do upper() and replace()
level = str(level).upper().replace(' ', '_').replace('-', '_')
assert level == expected_level
Copy link
Contributor Author

@jonathanblade jonathanblade Jan 31, 2024

Choose a reason for hiding this comment

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

@RobertCraigie I updated the tests and found here a bug in Prisma 😅

P.S. Look please at mypy (3.11) step why it doesn't pass.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh wow, thanks for reporting that!

The mypy failure is unrelated to your PR, I'll look into fixing it.

Copy link
Owner

Choose a reason for hiding this comment

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

If you rebase against main, the mypy job should pass now.

Copy link
Contributor Author

@jonathanblade jonathanblade Jan 31, 2024

Choose a reason for hiding this comment

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

I'll update docs, then wait for a response from the Prisma team, and if bug will be confirmed, then PR will be ready to final review 🎉

Copy link
Contributor Author

@jonathanblade jonathanblade Feb 2, 2024

Choose a reason for hiding this comment

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

I'll update docs, then wait for a response from the Prisma team, and if bug will be confirmed, then PR will be ready to final review 🎉

Answer: prisma/prisma#22890 (comment)

Copy link
Owner

Choose a reason for hiding this comment

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

of course mysql doesn't even have a way to query that 🤦

I think it would be fine to just skip the tests for mysql if you haven't already.

Copy link
Contributor Author

@jonathanblade jonathanblade Feb 2, 2024

Choose a reason for hiding this comment

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

Sorry, I didn't know that...

It marked with skipif.

@jonathanblade jonathanblade force-pushed the main branch 3 times, most recently from 4991b5a to ac76cbb Compare January 31, 2024 11:35
@jonathanblade jonathanblade force-pushed the main branch 10 times, most recently from 68fa3d7 to ef194c1 Compare February 10, 2024 13:01
@jonathanblade jonathanblade force-pushed the main branch 8 times, most recently from 69cc396 to b31265b Compare February 14, 2024 07:01
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
This will be helpful for transaction isolation levels support

#878
RobertCraigie added a commit that referenced this pull request Feb 24, 2024
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.

Add support for interactive transactions with an isolation level
2 participants