Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 6f73ea1

Browse files
authored
fix: Calling commit and _json_body make raising an exception when any datapoints are not added. (#772)
* If any SerialHelper is not generated, calling the commit function makes raising an exception because _datapoints is not allocated. It is hard to find the reason of this error. it is because reviewing influxdb-python's code is needed. I think that it is important that is producing predictable results. Results when calling first time is needed to equal to calling resetting datapoints in json_body. So, I've fixed that if not initialized when calling _json_body() function, _datapoints is reset to avoid raising error. In Unittest, the setup function is added. When calling setup function firstly, __initialized__ is False and _datapoints is not assigned. But, because of this commit, it is OK. Contacts: Keunhyun Oh <keunhyun.oh@ahnlab.com> * fix build fail Contacts: Keunhyun Oh <keunhyun.oh@ahnlab.com> * fix build fail Contacts: Keunhyun Oh <keunhyun.oh@ahnlab.com> * fix build fail Contacts: Keunhyun Oh <keunhyun.oh@ahnlab.com> * Update helper_test.py * Update helper_test.py * Update helper_test.py
1 parent 6290994 commit 6f73ea1

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

influxdb/helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def _json_body_(cls):
174174
:return: JSON body of these datapoints.
175175
"""
176176
json = []
177+
if not cls.__initialized__:
178+
cls._reset_()
177179
for series_name, data in six.iteritems(cls._datapoints):
178180
for point in data:
179181
json_point = {

influxdb/influxdb08/helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def _json_body_(cls):
139139
:return: JSON body of the datapoints.
140140
"""
141141
json = []
142+
if not cls.__initialized__:
143+
cls._reset_()
142144
for series_name, data in six.iteritems(cls._datapoints):
143145
json.append({'name': series_name,
144146
'columns': cls._fields,

influxdb/tests/helper_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class Meta:
4747

4848
TestSeriesHelper.MySeriesHelper = MySeriesHelper
4949

50+
def setUp(self):
51+
"""Check that MySeriesHelper has empty datapoints."""
52+
super(TestSeriesHelper, self).setUp()
53+
self.assertEqual(
54+
TestSeriesHelper.MySeriesHelper._json_body_(),
55+
[],
56+
'Resetting helper in teardown did not empty datapoints.')
57+
5058
def tearDown(self):
5159
"""Deconstruct the TestSeriesHelper object."""
5260
super(TestSeriesHelper, self).tearDown()

0 commit comments

Comments
 (0)