From 1ab4be521566ced97a1f0d6860d2ae1d548d368a Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Thu, 5 Dec 2019 23:55:29 +0900 Subject: [PATCH 1/7] 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 --- influxdb/helper.py | 2 ++ influxdb/influxdb08/helper.py | 2 ++ influxdb/tests/helper_test.py | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/influxdb/helper.py b/influxdb/helper.py index e622526d..760c6006 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -154,6 +154,8 @@ def _json_body_(cls): :return: JSON body of these datapoints. """ json = [] + if not cls.__initialized__: + cls._reset_() for series_name, data in six.iteritems(cls._datapoints): for point in data: json_point = { diff --git a/influxdb/influxdb08/helper.py b/influxdb/influxdb08/helper.py index f3dec33c..5f2d4614 100644 --- a/influxdb/influxdb08/helper.py +++ b/influxdb/influxdb08/helper.py @@ -139,6 +139,8 @@ def _json_body_(cls): :return: JSON body of the datapoints. """ json = [] + if not cls.__initialized__: + cls._reset_() for series_name, data in six.iteritems(cls._datapoints): json.append({'name': series_name, 'columns': cls._fields, diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index 6f24e85d..9dc2104a 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -47,6 +47,13 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper + def setUp(self): + super(TestSeriesHelper, self).setUp() + self.assertEqual( + TestSeriesHelper.MySeriesHelper._json_body_(), + [], + 'Initializing helper and resetting helper in teardown did not empty datapoints.') + def tearDown(self): """Deconstruct the TestSeriesHelper object.""" super(TestSeriesHelper, self).tearDown() From 952e13f427dbed0c33683b732ab5e11087b3a478 Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Fri, 6 Dec 2019 00:41:36 +0900 Subject: [PATCH 2/7] fix build fail Contacts: Keunhyun Oh --- influxdb/tests/helper_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index 9dc2104a..fe5bdfcf 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -48,11 +48,12 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper def setUp(self): + """Check not initialized datapoints's not raising exception and resetting helper""" super(TestSeriesHelper, self).setUp() self.assertEqual( TestSeriesHelper.MySeriesHelper._json_body_(), [], - 'Initializing helper and resetting helper in teardown did not empty datapoints.') + 'Resetting helper in teardown did not empty datapoints.') def tearDown(self): """Deconstruct the TestSeriesHelper object.""" From 53b1129d0eec988bdeb128a700f74d6a6d80b759 Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Fri, 6 Dec 2019 01:14:56 +0900 Subject: [PATCH 3/7] fix build fail Contacts: Keunhyun Oh --- influxdb/tests/helper_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index fe5bdfcf..69c7af39 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -48,7 +48,7 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper def setUp(self): - """Check not initialized datapoints's not raising exception and resetting helper""" + """Check not initialized datapoints's not raising exception and resetting helper.""" super(TestSeriesHelper, self).setUp() self.assertEqual( TestSeriesHelper.MySeriesHelper._json_body_(), From f3d2a90ce31a083230fe804a503a411d38990609 Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Fri, 6 Dec 2019 07:10:25 +0900 Subject: [PATCH 4/7] fix build fail Contacts: Keunhyun Oh --- influxdb/tests/helper_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index 69c7af39..3ff5b8ff 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -48,7 +48,8 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper def setUp(self): - """Check not initialized datapoints's not raising exception and resetting helper.""" + """Check not initialized datapoints's not raising exception + and resetting helper.""" super(TestSeriesHelper, self).setUp() self.assertEqual( TestSeriesHelper.MySeriesHelper._json_body_(), From f0845cfc362b5710a286a89ccf60eb164a7a0053 Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Fri, 6 Dec 2019 11:32:18 +0900 Subject: [PATCH 5/7] Update helper_test.py --- influxdb/tests/helper_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index 3ff5b8ff..b581e06b 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -48,8 +48,10 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper def setUp(self): - """Check not initialized datapoints's not raising exception - and resetting helper.""" + """ + Check not initialized datapoints's not raising exception + and resetting helper. + """ super(TestSeriesHelper, self).setUp() self.assertEqual( TestSeriesHelper.MySeriesHelper._json_body_(), From a02c46a21a9520de0b3d3f0cabbb5505d81a7c94 Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Fri, 6 Dec 2019 13:15:39 +0900 Subject: [PATCH 6/7] Update helper_test.py --- influxdb/tests/helper_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index b581e06b..df7caaf9 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -48,10 +48,7 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper def setUp(self): - """ - Check not initialized datapoints's not raising exception - and resetting helper. - """ + """Check that MySeriesHelper has empty datapoints""" super(TestSeriesHelper, self).setUp() self.assertEqual( TestSeriesHelper.MySeriesHelper._json_body_(), From 0362f73c9b745560d6cc5b43a2b4dc5d1d59a0c1 Mon Sep 17 00:00:00 2001 From: Keunhyun Oh Date: Fri, 6 Dec 2019 13:15:52 +0900 Subject: [PATCH 7/7] Update helper_test.py --- influxdb/tests/helper_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index df7caaf9..a73dd5df 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -48,7 +48,7 @@ class Meta: TestSeriesHelper.MySeriesHelper = MySeriesHelper def setUp(self): - """Check that MySeriesHelper has empty datapoints""" + """Check that MySeriesHelper has empty datapoints.""" super(TestSeriesHelper, self).setUp() self.assertEqual( TestSeriesHelper.MySeriesHelper._json_body_(),