Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

fix: setting 64bit fields from strings supported - #267

Merged
software-dov merged 5 commits into
googleapis:masterfrom
software-dov:stringy-int64
Oct 25, 2021
Merged

fix: setting 64bit fields from strings supported#267
software-dov merged 5 commits into
googleapis:masterfrom
software-dov:stringy-int64

Conversation

@software-dov

@software-dovsoftware-dov commented Oct 20, 2021

Copy link
Copy Markdown
Contributor

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.

classSquid(proto.Message):
mass_kg=proto.Field(proto.INT64, number=1)
s=Squid(mass_kg=10)
s_dict=Squid.to_dict(s)
asserts==Squid(s_dict)
s.mass_kg="20"# Supported

@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Oct 20, 2021
@codecov

codecovBot commented Oct 20, 2021

Copy link
Copy Markdown

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 FilesCoverage Δ
proto/modules.py100.00% <ø> (ø)
proto/enums.py100.00% <100.00%> (ø)
proto/fields.py100.00% <100.00%> (ø)
proto/marshal/collections/repeated.py100.00% <100.00%> (ø)
proto/marshal/marshal.py100.00% <100.00%> (ø)
proto/marshal/rules/bytes.py100.00% <100.00%> (ø)
proto/marshal/rules/message.py100.00% <100.00%> (ø)
proto/marshal/rules/stringy_numbers.py100.00% <100.00%> (ø)
proto/message.py100.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
Comment threaddocs/marshal.rst Outdated
Comment threaddocs/marshal.rst Outdated
Comment threaddocs/marshal.rst Outdated
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
Copy Markdown

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-clagoogle-claBot 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
Copy Markdown
Contributor

@googlebot I consent.

@google-cla

Copy link
Copy Markdown

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
Copy Markdown
Contributor

@googlebot I fixed it.

@google-cla

Copy link
Copy Markdown

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
Copy Markdown
Contributor

@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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@software-dovsoftware-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:masterOct 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-dovsoftware-dov linked an issue Oct 26, 2021 that may be closed by this pull request
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Nov 24, 2025
* 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
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yesThis 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

@software-dov@tseaver@kbandes@busunkim96