Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: add missing handler for deserializing json value#1587

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@tomwojcik
Copy link
Contributor

Fixes#1500

@tomwojciktomwojcik requested review froma team ascode ownersJune 19, 2023 10:59
@tomwojciktomwojcik requested a review fromtswastJune 19, 2023 10:59
@google-cla
Copy link

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View thisfailed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-labelproduct-auto-labelbot added size: sPull request size is small. api: bigqueryIssues related to the googleapis/python-bigquery API. labelsJun 19, 2023
@tomwojcik
Copy link
ContributorAuthor

tomwojcik commentedJul 2, 2023
edited
Loading

@tswast bump, please review

@partheaparthea added kokoro:runAdd this label to force Kokoro to re-run the tests. kokoro:force-runAdd this label to force Kokoro to re-run the tests. owlbot:runAdd this label to trigger the Owlbot post processor. labelsJul 6, 2023
@gcf-owl-botgcf-owl-botbot removed the owlbot:runAdd this label to trigger the Owlbot post processor. labelJul 6, 2023
@yoshi-kokoroyoshi-kokoro removed kokoro:runAdd this label to force Kokoro to re-run the tests. kokoro:force-runAdd this label to force Kokoro to re-run the tests. labelsJul 6, 2023
@tswasttswast added the kokoro:runAdd this label to force Kokoro to re-run the tests. labelOct 3, 2023
@yoshi-kokoroyoshi-kokoro removed the kokoro:runAdd this label to force Kokoro to re-run the tests. labelOct 3, 2023
Copy link
Contributor

@tswasttswast left a comment

Choose a reason for hiding this comment

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

Thanks!

One concern I have is the other direction. If someone supplies a parsed JSON object to an API likeinsert_rows, do we correctly serialize that?

@LinchinLinchin added the kokoro:force-runAdd this label to force Kokoro to re-run the tests. labelNov 1, 2023
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-runAdd this label to force Kokoro to re-run the tests. labelNov 1, 2023
@tswasttswast added the kokoro:runAdd this label to force Kokoro to re-run the tests. labelDec 13, 2023
@yoshi-kokoroyoshi-kokoro removed the kokoro:runAdd this label to force Kokoro to re-run the tests. labelDec 13, 2023
@tswast
Copy link
Contributor

Looks like everything is working well except for the type annotations:

nox > Running session mypynox > Creating virtual environment (virtualenv) using python3.8 in .nox/mypynox > python -m pip install -e '.[all]'nox > python -m pip install mypy==1.6.1nox > python -m pip install types-protobuf types-python-dateutil types-requests types-setuptoolsnox > mypy -p google --show-tracebackgoogle/cloud/bigquery/query.py:472: error: Cannot call function of unknown type  [operator]google/cloud/bigquery/query.py:629: error: Cannot call function of unknown type  [operator]google/cloud/bigquery/query.py:778: error: Cannot call function of unknown type  [operator]Found 3 errors in 1 file (checked 54 source files)nox > Command mypy -p google --show-traceback failed with exit code 1nox > Session mypy failed.
tomwojcik reacted with rocket emoji

@tswasttswast self-assigned thisDec 13, 2023
@tswasttswast added kokoro:runAdd this label to force Kokoro to re-run the tests. owlbot:runAdd this label to trigger the Owlbot post processor. labelsDec 13, 2023
@gcf-owl-botgcf-owl-botbot removed the owlbot:runAdd this label to trigger the Owlbot post processor. labelDec 13, 2023
@yoshi-kokoroyoshi-kokoro removed the kokoro:runAdd this label to force Kokoro to re-run the tests. labelDec 13, 2023
@tswasttswast merged commit09017a9 intogoogleapis:mainDec 13, 2023
@tomwojciktomwojcik deleted the feature/#1500-jsonfield-deserialize branchDecember 13, 2023 22:48
@MartijnvanElferen
Copy link

This change is causing the following error forinsert_rows:

TypeError: _json_from_json() missing 1 required positional argument: 'field'

Is there a recommended fix for this?

@tswast
Copy link
Contributor

Thanks@MartijnvanElferen for the report. I've filed#1756 to investigate further.

@tswast
Copy link
Contributor

As a workaroundinsert_rows_json should avoid this type conversion code, but you're responsible for putting things in a format the BigQuery REST API understands.

@tswast
Copy link
Contributor

@MartijnvanElferen Fix pending:#1757

Note: this PR will change the behavior of JSON data ininsert_rows to calljson.dumps, which is consistent with the new behavior of callingjson.loads when reading row values. Previously, JSON support was happening via a generic fallback that didn't do any conversion of values passed in.

@MartijnvanElferen
Copy link

Thanks,@tswast. I'll refactor a couple of things to avoid the type conversion. Looking forward to the fix at the same time!

@kcooney
Copy link

kcooney commentedMay 31, 2024
edited
Loading

@tswast This change should probably be listed as a potentially braking change in the release notes, since before this change reading the entire column would return a value of typestr:

CREATETABLEmydataset.table(  id INT64,  proto_as_json JSON);
fromgoogle.cloudimportbigqueryfromgoogle.protobufimportjson_formatfromcom.example.my_proto_pb2importMyProtoclient=bigquery.Client()proto=MyProto(first_name="Jane",last_name="Doe")proto_as_json=json_format.MessageToJson(proto,use_integers_for_enums=True,indent=None)rows_to_insert= [    {"id":1,"proto_as_json":f'JSON """{proto_as_json}"""'},]errors=client.insert_rows("mydataset.table",rows_to_insert)assertnoterrorsrow=client.query("SELECT proto_as_json FROM mydataset.table").result().__next__()json_str=row["proto_as_json"]# Prior to this change, json_str was of type str, so we could do this:read_proto=MyProto()json_format.Parse(json_str,read_proto)assertproto==read_proto

Luckily, in our project we created a common helper method for thejson_format.Parse() call, so we can update it to usejson_format.ParseDict()

@tswast
Copy link
Contributor

Yeah, it's a gray area with this since we never said we support the JSON type until this change.

We still don't support JSON in some code paths like to_dataframe()

@kcooney
Copy link

kcooney commentedMay 31, 2024
edited
Loading

@tswast We saw the breakage when we tried to update a number of python libraries to newer versions. The release notes were very unhelpful in determining which library and version could have caused the problem (because the PR and bug listed in the release notes suggested that it only affected selecting subfields). It wasn't until we found a work around that we were able to track the issue to v3.15.0 and this change. Even if there were no prior promises of support of the JSON type, a short blurb in the release notes would be very much appreciated.

ebracho reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tswasttswasttswast approved these changes

@chalmerlowechalmerloweAwaiting requested review from chalmerlowe

Assignees

@tswasttswast

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.size: sPull request size is small.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Deserializing JSON subfields within structs fails

7 participants

@tomwojcik@tswast@MartijnvanElferen@kcooney@parthea@Linchin@yoshi-kokoro

[8]ページ先頭

©2009-2025 Movatter.jp