@cryptotaxi247 / netdata-1 / commits / 2c565d441

Remove deprecated API call (#5326)

Using `with connection as cursor` has been deprecated in 2017 and now with 1.4.0 the API call has been removed. Therefore the cursor needs to be created and closed "manually"

Andre Lehmann committed Feb 4, 2019 at 22:09 UTC 2c565d4415a537c2e3cafcb3bdbbf698e25b6786
1 file changed +16 -14
collectors/python.d.plugin/python_modules/bases/FrameworkServices/MySQLService.py
+16 -14
@@ -131,20 +131,22 @@ class MySQLService(SimpleService):
131 raw_data = dict()
132 queries = dict(self.queries)
133 try:
134 - with self.__connection as cursor:
135 - for name, query in queries.items():
136 - try:
137 - cursor.execute(query)
138 - except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as error:
139 - if self.__is_error_critical(err_class=exc_info()[0], err_text=str(error)):
140 - raise RuntimeError
141 - self.error('Removed query: {name}[{query}]. Error: error'.format(name=name,
142 - query=query,
143 - error=error))
144 - self.queries.pop(name)
145 - continue
146 - else:
147 - raw_data[name] = (cursor.fetchall(), cursor.description) if description else cursor.fetchall()
134 + cursor = self.__connection.cursor()
135 + for name, query in queries.items():
136 + try:
137 + cursor.execute(query)
138 + except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as error:
139 + if self.__is_error_critical(err_class=exc_info()[0], err_text=str(error)):
140 + cursor.close()
141 + raise RuntimeError
142 + self.error('Removed query: {name}[{query}]. Error: error'.format(name=name,
143 + query=query,
144 + error=error))
145 + self.queries.pop(name)
146 + continue
147 + else:
148 + raw_data[name] = (cursor.fetchall(), cursor.description) if description else cursor.fetchall()
149 + cursor.close()
150 self.__connection.commit()
151 except (MySQLdb.MySQLError, RuntimeError, TypeError, AttributeError):
152 self.__connection.close()