Explorar o código

HUE-8737 [py3] Handle PEP 479 Py3.8 generator raised StopIteration

Romain %!s(int64=5) %!d(string=hai) anos
pai
achega
f411939ff7
Modificáronse 1 ficheiros con 19 adicións e 15 borrados
  1. 19 15
      desktop/libs/notebook/src/notebook/models.py

+ 19 - 15
desktop/libs/notebook/src/notebook/models.py

@@ -57,22 +57,26 @@ LOG = logging.getLogger(__name__)
 def escape_rows(rows, nulls_only=False, encoding=None):
   data = []
 
-  for row in rows:
-    escaped_row = []
-    for field in row:
-      if isinstance(field, numbers.Number):
-        if math.isnan(field) or math.isinf(field):
-          escaped_field = json.dumps(field)
+  try:
+    for row in rows:
+      escaped_row = []
+
+      for field in row:
+        if isinstance(field, numbers.Number):
+          if math.isnan(field) or math.isinf(field):
+            escaped_field = json.dumps(field)
+          else:
+            escaped_field = field
+        elif field is None:
+          escaped_field = 'NULL'
         else:
-          escaped_field = field
-      elif field is None:
-        escaped_field = 'NULL'
-      else:
-        escaped_field = smart_unicode(field, errors='replace', encoding=encoding) # Prevent error when getting back non utf8 like charset=iso-8859-1
-        if not nulls_only:
-          escaped_field = escape(escaped_field).replace(' ', ' ')
-      escaped_row.append(escaped_field)
-    data.append(escaped_row)
+          escaped_field = smart_unicode(field, errors='replace', encoding=encoding) # Prevent error when getting back non utf8 like charset=iso-8859-1
+          if not nulls_only:
+            escaped_field = escape(escaped_field).replace(' ', ' ')
+        escaped_row.append(escaped_field)
+      data.append(escaped_row)
+  except RuntimeError:
+    pass  # pep-0479: expected Py3.8 generator raised StopIteration
 
   return data