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.

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.

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