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

get_transaction failed when cache_allowed_requests is set to True. #3506

Open
wangereth opened this issue Oct 9, 2024 · 2 comments · May be fixed by #3508
Open

get_transaction failed when cache_allowed_requests is set to True. #3506

wangereth opened this issue Oct 9, 2024 · 2 comments · May be fixed by #3508

Comments

@wangereth
Copy link

wangereth commented Oct 9, 2024

What happened?

When set cache_allowed_requests in HTTPProvider, and assign get_transaction result to a variable, there will be an exception.

Code that produced the error

from web3 import Web3
# test on bsc chain
w3 = Web3(
    Web3.HTTPProvider(
        "http://127.0.0.1:8545",  cache_allowed_requests=True
    )
)

txhash = 0xd7caec490f96319fee3b06ac2ad0f7bb03ecf8cc464304b256a51dcd34ea50cc
txdata = w3.eth.get_transaction(txhash)

Full error output

There was an exception while caching the request.
Traceback (most recent call last):
  File "lib/python3.12/site-packages/web3/_utils/caching/request_caching_validation.py", line 39, in is_beyond_validation_threshold
    return blocknum <= to_int(hexstr=response["result"]["number"])
                                     ~~~~~~~~~~~~~~~~~~^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Fill this section in if you know how this could or should be fixed

No response

web3 Version

7.3.0

Python Version

3.12.3

Operating System

osx

Output from pip freeze

No response

@fselmo
Copy link
Collaborator

fselmo commented Oct 9, 2024

That was a bit of oversight on my part with implementation since this focuses on POS values. But this needs to be addressed. For now, you can get unstuck caching all requests by setting request_cache_validation_threshold=None on the provider. This will make it so it behaves like it used to, where no validation is enforced for those internally validated endpoints, caching all get_transaction requests - so keep that in mind.

I think a decent way to address this might be to use something like a time interval value, with some defaults dependent on the chain id for some of the bigger chains and have a reasonable default for all other chains. as the validation threshold. And if the user wants to cache everything they can still set it to None or set their own time interval based o. Their chain's finality mechanism.

I'll get working on fixing this but I hope you can get unstuck for now.

@wangereth
Copy link
Author

Thank you, I appreciate your response and it works.

@fselmo fselmo linked a pull request Oct 10, 2024 that will close this issue
3 tasks
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 a pull request may close this issue.

2 participants