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: setting 64bit fields from strings supported #267

Merged
merged 5 commits into from
Oct 25, 2021

Conversation

software-dov
Copy link
Contributor

@software-dov software-dov commented Oct 20, 2021

Due to limitations in certain browser/javascript combinations,
fields that are 64 bit integer types are converted to strings when
encoding a message to JSON or a dict.
Decoding from JSON handles this explicitly, but it makes converting
back from a dict an error.

This fix adds support for setting these 64 bit fields explicitly from
strings.

E.g.

class Squid(proto.Message):
      mass_kg = proto.Field(proto.INT64, number=1)

s = Squid(mass_kg=10)
s_dict = Squid.to_dict(s)

assert s == Squid(s_dict)
s.mass_kg = "20"            # Supported

@software-dov software-dov requested review from busunkim96, arithmetic1728 and a team October 20, 2021 22:52
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 20, 2021
@codecov
Copy link

codecov bot commented Oct 20, 2021

Codecov Report

Merging #267 (b50c91d) into master (6a43682) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #267   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        22    +2     
  Lines          862       961   +99     
  Branches       149       170   +21     
=========================================
+ Hits           862       961   +99     
Impacted Files Coverage Δ
proto/modules.py 100.00% <ø> (ø)
proto/enums.py 100.00% <100.00%> (ø)
proto/fields.py 100.00% <100.00%> (ø)
proto/marshal/collections/repeated.py 100.00% <100.00%> (ø)
proto/marshal/marshal.py 100.00% <100.00%> (ø)
proto/marshal/rules/bytes.py 100.00% <100.00%> (ø)
proto/marshal/rules/message.py 100.00% <100.00%> (ø)
proto/marshal/rules/stringy_numbers.py 100.00% <100.00%> (ø)
proto/message.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update debd16f...b50c91d. Read the comment docs.

Due to limitations in certain browser/javascript combinations,
fields that are 64 bit integer types are converted to strings when
encoding a message to JSON or a dict.
Decoding from JSON handles this explicitly, but it makes converting
back from a dict an error.

This fix adds support for setting these 64 bit fields explicitly from
strings.

E.g.

class Squid(proto.Message):
      mass_kg = proto.Field(proto.INT64, number=1)

s = Squid(mass_kg=10)
s_dict = Squid.to_dict(s)

assert s == Squid(**s_dict) # Supported
assert s == Squid(s_dict)   # NOT supported for performance reasons
s.mass_kg = "20"            # Supported
docs/marshal.rst Outdated Show resolved Hide resolved
docs/marshal.rst Outdated Show resolved Hide resolved
docs/marshal.rst Outdated Show resolved Hide resolved
vam-google added a commit to vam-google/gapic-generator-python that referenced this pull request Oct 22, 2021
This includes
1) Do not include asyncio tests in the generated tests, because rest transport does not have asynio client.
2) Generate body field mock values for generated tests (otherwise grpc transcodding logic would fail).
3) Make `always_use_jwt_access=True` default for rest clients (grpc already does that) to match expected calls in generated tests.
4) Fix mypy errors for `AuthorizedSession` by ignoring it
5) Include operations_v1 conditionally, only if the client has lro

There are few more fixes left, which are expected to be fixed in separate PRs.

1) `message->to_dict->message` roundrtip problem for int64 types is expected to be fixed by googleapis/proto-plus-python#267
2) builtins conflicts (`license_` vs `license` as field name) is expected to be fixed by a TBD PR
Co-authored-by: Tres Seaver <tseaver@palladion.com>
@google-cla
Copy link

google-cla bot commented Oct 25, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Oct 25, 2021
@tseaver
Copy link
Contributor

tseaver commented Oct 25, 2021

@googlebot I consent.

@google-cla
Copy link

google-cla bot commented Oct 25, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@tseaver
Copy link
Contributor

tseaver commented Oct 25, 2021

@googlebot I fixed it.

@google-cla
Copy link

google-cla bot commented Oct 25, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@tseaver
Copy link
Contributor

tseaver commented Oct 25, 2021

@software-dov Ugh, I'm sorry -- the CLA bot has lost its wig again.

Add test and impl for deeply nested messages with 64 bit int fields
Remove doc changes
@google-cla
Copy link

google-cla bot commented Oct 25, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Oct 25, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

# If we have a type error,
# try the slow path in case the error
# was an int64/string issue
return self._wrapper(value)._pb
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay! that is a waaaay better devx.


c2 = Clam(c_dict)

assert c == c2
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent roundtrip demo.

@tseaver
Copy link
Contributor

tseaver commented Oct 25, 2021

@software-dov You'll have to flip the cla: no label to cla: yes manually.

@software-dov software-dov added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Oct 25, 2021
@software-dov software-dov merged commit ea7b911 into googleapis:master Oct 25, 2021
@software-dov software-dov deleted the stringy-int64 branch October 25, 2021 18:54
vam-google added a commit to googleapis/gapic-generator-python that referenced this pull request Oct 25, 2021
* fix: Fix rest transport logic

This includes
1) Do not include asyncio tests in the generated tests, because rest transport does not have asynio client.
2) Generate body field mock values for generated tests (otherwise grpc transcodding logic would fail).
3) Make `always_use_jwt_access=True` default for rest clients (grpc already does that) to match expected calls in generated tests.
4) Fix mypy errors for `AuthorizedSession` by ignoring it
5) Include operations_v1 conditionally, only if the client has lro

There are few more fixes left, which are expected to be fixed in separate PRs.

1) `message->to_dict->message` roundrtip problem for int64 types is expected to be fixed by googleapis/proto-plus-python#267
2) builtins conflicts (`license_` vs `license` as field name) is expected to be fixed by a TBD PR

* fix integration tests
@software-dov software-dov linked an issue Oct 26, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid type for user_id field returned by TransferConfig.to_dict
4 participants