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

service: Fix session type checks #436

Merged
merged 3 commits into from
Oct 9, 2023
Merged

Conversation

bkeryan
Copy link
Collaborator

@bkeryan bkeryan commented Oct 6, 2023

What does this Pull Request accomplish?

_with_typed_session() was incorrectly assuming that the runtime type matches the static type. Also, it was trying to infer the static type variable TSession based on the runtime type expression type(session).

Fixing this revealed a problem with the tests: patching driver.Session and replacing it with a mock causes isinstance checks to fail. The 2nd argument to isinstance must be a type, so it raises an error if driver.Session is a Mock instance rather than a type. Patching driver.Session.__new__ instead of driver.Session avoids this problem because it ensures that driver.Session is still a type. (Patching driver.Session to replace it with a subclass that overrides __new__ would also work.)

Why should this Pull Request be merged?

These type checks are needed for get_connection(s)

What testing has been done?

Ran updated unit tests.

Patching the Session class and replacing it with a Mock doesn't work
with isinstance() because an instance of Mock is not a type.
_with_typed_session() was incorrectly assuming that the runtime type matches the
static type. Also, it was trying to infer the static type variable
`TSession` based on the runtime type expression `type(session)`.
@github-actions
Copy link

github-actions bot commented Oct 7, 2023

Test Results

       30 files  ±0       30 suites  ±0   11m 4s ⏱️ - 1m 50s
     338 tests ±0     271 ✔️ ±0       67 💤 ±0  0 ±0 
10 110 runs  ±0  7 565 ✔️ ±0  2 545 💤 ±0  0 ±0 

Results for commit 17e5aca. ± Comparison against base commit ab73388.

♻️ This comment has been updated with latest results.

@bkeryan bkeryan merged commit 5b37adb into main Oct 9, 2023
20 checks passed
@bkeryan bkeryan deleted the users/bkeryan/session-type-checks branch October 9, 2023 19:37
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.

2 participants