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

Fix exception-swallowing code path #623

Merged
merged 4 commits into from
Aug 27, 2024
Merged

Fix exception-swallowing code path #623

merged 4 commits into from
Aug 27, 2024

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Aug 26, 2024

Fixes #624

This is a bug identified by pyright type checking.

How this was tested

  • PR includes two commits: a test that fails on main before the fix, and the fix.

I also confirmed manually that if the server responds with gRPC error ALREADY_EXISTS, but the error details do not satisfy the logic in the SDK code, then the user gets

UnboundLocalError: cannot access local variable 'resp' where it is not associated with a value

What they should get is temporalio.service.RPCError.

@dandavison dandavison marked this pull request as ready for review August 26, 2024 15:20
@dandavison dandavison requested a review from a team as a code owner August 26, 2024 15:20
@dandavison dandavison marked this pull request as draft August 26, 2024 15:21
@cretz
Copy link
Member

cretz commented Aug 26, 2024

👍 I saw this one the other day, but I don't remember the context or why I didn't create the issue (or can't find it)

@dandavison dandavison marked this pull request as ready for review August 26, 2024 16:38
@dandavison
Copy link
Contributor Author

dandavison commented Aug 26, 2024

Added a test based on monkey-patching the workflow_service method. PR has two commits:

  • The failing test
  • A fix

Ready for review.

@cretz
Copy link
Member

cretz commented Aug 26, 2024

Shouldn't need to monkey patch, should be easy enough to make whichever code path occur against a real server

@dandavison
Copy link
Contributor Author

dandavison commented Aug 26, 2024

Shouldn't need to monkey patch, should be easy enough to make whichever code path occur against a real server

Actually, monkey patching is more appropriate in this case. What we're trying to assert is that if the client receives an ALREADY_EXISTS gRPC error, it will always be raised, even if its details aren't of a particular form. There's no need for that to be an integration test involving a real server, and there are lots of arguments for it not to be (test suite execution speed, encouraging good test suite style, ease of understanding the test assertion, etc). Monkey–patching is a very standard approach in Python testing: it's explicitly supported by tools in the standard library (mock.patch).

@cretz
Copy link
Member

cretz commented Aug 26, 2024

I personally prefer the end to end integration test, and not too concerned about speed (we have an already-exists integration test already I think). We have dozens of tests using the server harmlessly to test actual client behavior in actual situations without advanced knowledge of inner workings. Patching is brittle IMO, but if you feel you must do it, ok.

@cretz
Copy link
Member

cretz commented Aug 26, 2024

EDIT: Nevermind, I misread the original code and thought we were swallowing more than just already-exist-wrong-details exceptions. Can ignore my desire for integration tests here.

@dandavison
Copy link
Contributor Author

You're right though! The test is a bit brittle. But yes here we're in a situation where there's a code path that's technically a bug, but not obvious how to repro it with a real interaction with a server, and yet we have an obligation to put in a test to back the fix.

@dandavison dandavison merged commit 7af99d0 into main Aug 27, 2024
12 checks passed
@dandavison dandavison deleted the fix-rpc-error-handling branch August 27, 2024 16:35
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.

[Bug] RPCStatusCode.ALREADY_EXISTS can be swallowed
2 participants