-
Notifications
You must be signed in to change notification settings - Fork 309
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: add warning when encountering unknown field types #1989
Conversation
The types returned for currently unsupported field types may change in the future, when support is added. Warn users that the types they are using are not yet supported.
google/cloud/bigquery/_helpers.py
Outdated
converter = _CELLDATA_FROM_JSON.get(field.field_type, lambda value, _: value) | ||
def default_converter(value, field): | ||
warnings.warn( | ||
"Unknown type '{}' for field '{}'.".format(field.field_type, field.name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be explicit and say "Behavior reading this type is not officially supported and may change in future." or something scary along those lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we mark this as "fixed", I think the inverse direction is needed too (where we write JSON from a record), which is used in methods like client.insert_rows()
(though maybe that already fails when encountering unknown types?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Yeah looks like
# Unknown fields should not be silently dropped, include them. Since there |
converter = _SCALAR_VALUE_TO_JSON_ROW.get(field.field_type) |
add warning for write and warn about future behavior changes
@@ -382,7 +378,16 @@ def _field_to_index_mapping(schema): | |||
|
|||
|
|||
def _field_from_json(resource, field): | |||
converter = _CELLDATA_FROM_JSON.get(field.field_type, lambda value, _: value) | |||
def default_converter(value, field): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can move this function to outside, so we can reuse it for _scalar_field_to_json()
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up just moving the warning itself to a new function, since the converter in _scalar_field_to_json has a different function signature.
I think the docs test isn't failing due to changes in this PR, it appears to relate to the docker image used. I will approve this PR and force merge. LGTM. |
Fixes #1988