-
Notifications
You must be signed in to change notification settings - Fork 1.8k
check _request_information_cache value is a dict before .get-ing from it #3663
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
Files not reviewed (1)
- newsfragments/3642.bugfix.rst: Language not supported
Comments suppressed due to low confidence (1)
web3/providers/persistent/persistent.py:336
- The indentation of the if-statement checking for 'error' is inconsistent with the surrounding block, which may cause unexpected behavior. Consider aligning it properly within the 'if isinstance(response, dict):' block.
if "error" in response and request is None:
@fselmo I've added the I applied it across all instances of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I wanted to suggest the decorator as I think that could DRY things up and reduce common surface area to one place.
Is there a reason to only apply it to the persistent provider?
This should be applied to all providers that support batching (as you did) 👍🏼
8fc338b
to
8590ae8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, just some refactor ideas to think about. It would also be good to have a simple test that actually checks this state. Given that we also do the dict check (the first commit in this PR), I don't think any tests actually fail without this implementation and then pass after it is implemented (correct me if I'm wrong here).
It doesn't have to be a super complex test but something that tracks this change in case we ever meddle with it and accidentally turn it off would be ideal.
74f3730
to
bcd1f8b
Compare
Tests added for all providers (except legacy websocket), and verified a failure when the decorator is commented out. I decided to not test legacy websocket because even when I got its test to pass, I couldn't get rid of the |
|
||
|
||
@pytest.mark.parametrize("initial_is_batching", [True, False]) | ||
def test_http_provider_is_batching_is_reset_to_false_after_batching_call( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of a test that checks both on and off behavior? Something like this:
@patch(
"web3._utils.http_session_manager.HTTPSessionManager.make_post_request",
new_callable=Mock,
)
def test_http_provider_is_batching_when_make_batch_request(mock_post):
def assert_is_batching_and_return_response(*_args, **_kwargs) -> bytes:
assert provider._is_batching
return b'{"jsonrpc":"2.0","id":1,"result":["0x1"]}'
provider = HTTPProvider()
assert not provider._is_batching
mock_post.side_effect = assert_is_batching_and_return_response
provider.make_batch_request([("eth_blockNumber", [])])
assert not provider._is_batching
That way we check that it turns on while we are making the post request and that it turns back off after the call. We could add a similar test across all the providers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, all updated to the new pattern. Thanks!
lgtm once tests pass 👌🏼 (all good on the legacy ws, I agree on the deprecation reasoning) |
What was wrong?
Mixing batching and non-batching calls causing issues.
Closes #3642
How was it fixed?
dict
beforeget
ting from it.try/finally
blocks (via a decorator) to allmake_batch_request
functions to make sure_is_batching
isTrue
when called and reset toFalse
afterwards.Todo:
Cute Animal Picture