Skip to content
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

chore: add detail error message for not supported type of Point.field #241

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features
1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination.
1. [#241](https://github.com/influxdata/influxdb-client-python/pull/241): Add detail error message for not supported type of `Point.field`

## 1.17.0 [2021-04-30]

Expand Down
2 changes: 1 addition & 1 deletion influxdb_client/client/write/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _append_fields(fields):
elif isinstance(value, str):
_return.append(f'{_escape_key(field)}="{_escape_string(value)}"')
else:
raise ValueError()
raise ValueError(f'Type: "{type(value)}" of field: "{field}" is not supported.')

return f"{','.join(_return)}"

Expand Down
10 changes: 10 additions & 0 deletions tests/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ def test_points_from_different_timezones(self):
point_hk = Point.measurement("h2o").field("val", 1).time(time_in_hk)
self.assertEqual(point_utc.to_line_protocol(), point_hk.to_line_protocol())

def test_unsupported_field_type(self):
with self.assertRaises(ValueError) as ve:
Point.measurement("h2o") \
.tag("location", "europe") \
.field("level", UTC) \
.to_line_protocol()
exception = ve.exception

self.assertEqual('Type: "<class \'pytz.UTC\'>" of field: "level" is not supported.', f'{exception}')


if __name__ == '__main__':
unittest.main()