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: invalid conversion of timezone-aware datetime values to JSON#480

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
plamut merged 4 commits intogoogleapis:masterfromplamut:iss-476
Jan 25, 2021

Conversation

@plamut
Copy link
Contributor

Fixes#476.

This PR fixes converting timezone-aware datetime values to an UTC JSON string.

PR checklist:

  • Make sure to open an issue as abug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@plamutplamut requested review froma team andshollyman and removed request fora teamJanuary 21, 2021 15:19
@product-auto-labelproduct-auto-labelbot added the api: bigqueryIssues related to the googleapis/python-bigquery API. labelJan 21, 2021
@google-clagoogle-clabot added the cla: yesThis human has signed the Contributor License Agreement. labelJan 21, 2021
@plamutplamut changed the titleIss 476fix: invalid conversion of timezone-aware datetime values to JSONJan 21, 2021
def_timestamp_to_json_row(value):
"""Coerce 'value' to an JSON-compatible representation."""
ifisinstance(value,datetime.datetime):
# For naive datetime objects UTC timezone is assumed, thus we format
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this always our assumption? Based on the unit tests, I suppose so?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Can't say if "always", but the_datetime_to_json() helper has been unchanged since 2017 and was supposedly doing its job fine with naive datetime objects in this time - at least I don't remember any reported issues related to timezones. Thestrftime() conversion just uses thedatetime fields at their face value and ignores anytzinfo set.

Considering that naive datetimes are used most of the time (as opposed to timezone-aware datetime objects) and that users did not complain, the UTC timezone assumption was apparently correct behavior. The logic just failed to cover the case when somebody actually used a timezone-aware instance.

And indeed, unit tests expect the same, a naivedatetime instance is supposed to be converted to a string representation with a zero offset from UTC (example).

@plamutplamut requested a review fromtswastJanuary 25, 2021 12:16
@plamutplamut merged commit61b4385 intogoogleapis:masterJan 25, 2021
@plamutplamut deleted the iss-476 branchJanuary 25, 2021 17:04
gcf-merge-on-greenbot pushed a commit that referenced this pull requestJan 27, 2021
🤖 I have created a release \*beep\* \*boop\* ---## [2.7.0](https://www.github.com/googleapis/python-bigquery/compare/v2.6.2...v2.7.0) (2021-01-27)### Bug Fixes* invalid conversion of timezone-aware datetime values to JSON ([#480](https://www.github.com/googleapis/python-bigquery/issues/480)) ([61b4385](https://www.github.com/googleapis/python-bigquery/commit/61b438523d305ce66a68fde7cb49e9abbf0a8d1d))* reading the labels attribute on Job instances ([#471](https://www.github.com/googleapis/python-bigquery/issues/471)) ([80944f0](https://www.github.com/googleapis/python-bigquery/commit/80944f080bcc4fda870a6daf1d884de616d39ae7))* use explicitly given project over the client's default project for load jobs ([#482](https://www.github.com/googleapis/python-bigquery/issues/482)) ([530e1e8](https://www.github.com/googleapis/python-bigquery/commit/530e1e8d8fe8939e914a78ff1b220907c1b87af7))### Dependencies* declare support for Python 3.9 ([#488](https://www.github.com/googleapis/python-bigquery/issues/488)) ([55daa7d](https://www.github.com/googleapis/python-bigquery/commit/55daa7da9857a8a2fb14a80a4efa3f466386a85f))---This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tswasttswasttswast approved these changes

@shollymanshollymanAwaiting requested review from shollyman

Assignees

No one assigned

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BigQuery python cli fails to change time, BUT does changes timezone for TIMESTAMP which leads to an incorrect time

2 participants

@plamut@tswast

[8]ページ先頭

©2009-2025 Movatter.jp