Skip to content

fixed faulty dict access syntax which causes an attribute error #1040

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

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ def parse_block_identifier(web3, block_identifier):
elif block_identifier in ['latest', 'earliest', 'pending']:
return block_identifier
elif isinstance(block_identifier, bytes) or is_hex_encoded_block_hash(block_identifier):
return web3.eth.getBlock(block_identifier).number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @dylanjw @carver @voith just in case you don't see this. This is a good example of why we should be as diligent as possible to not assume the AttributeDict API is usable within our own web3 apis. Forgive me for preaching to the choir if you're already aware.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, replacing all the middlewares as the user did in #1039 is almost definitely not what they wanted to do. There will be a lot of things that work incorrectly, like: fields won't be converted to and from python native types. I'm not suggesting that we should encourage attribute syntax, but this is only one of many things that will work in unexpected ways if the user drops all the middleware.

return web3.eth.getBlock(block_identifier)['number']
else:
raise BlockNumberOutofRange

Expand All @@ -1425,7 +1425,7 @@ def parse_block_identifier_int(web3, block_identifier_int):
if block_identifier_int >= 0:
block_num = block_identifier_int
else:
last_block = web3.eth.getBlock('latest').number
last_block = web3.eth.getBlock('latest')['number']
block_num = last_block + block_identifier_int + 1
if block_num < 0:
raise BlockNumberOutofRange
Expand Down