-
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
Changes from 8 commits
a3efe4a
fa8329f
f382169
f4e006f
83ee4aa
d1d1eb4
a379e7b
93dda16
2be2830
094e7dc
f29bb05
c0b6272
be54ee5
a253165
cce5596
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ | |||||
import math | ||||||
import re | ||||||
import os | ||||||
import warnings | ||||||
from typing import Optional, Union | ||||||
|
||||||
from dateutil import relativedelta | ||||||
|
@@ -297,12 +298,7 @@ def _record_from_json(value, field): | |||||
record = {} | ||||||
record_iter = zip(field.fields, value["f"]) | ||||||
for subfield, cell in record_iter: | ||||||
converter = _CELLDATA_FROM_JSON[subfield.field_type] | ||||||
if subfield.mode == "REPEATED": | ||||||
value = [converter(item["v"], subfield) for item in cell["v"]] | ||||||
else: | ||||||
value = converter(cell["v"], subfield) | ||||||
record[subfield.name] = value | ||||||
record[subfield.name] = _field_from_json(cell["v"], subfield) | ||||||
return record | ||||||
|
||||||
|
||||||
|
@@ -382,7 +378,14 @@ 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): | ||||||
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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Yeah looks like
|
||||||
FutureWarning, | ||||||
) | ||||||
return value | ||||||
|
||||||
converter = _CELLDATA_FROM_JSON.get(field.field_type, default_converter) | ||||||
if field.mode == "REPEATED": | ||||||
return [converter(item["v"], field) for item in resource] | ||||||
else: | ||||||
|
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.