From af1564d410050f3aec1adb558d5653f04807daa9 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Tue, 17 May 2022 17:55:40 +0200 Subject: [PATCH] (core) Convert row tuples to lists to fix excel import error Summary: openpyxl was producing tuples while some older code expects lists. Choosing to convert the tuples to lists (instead of making the other code work with tuples) in case there's other similar issues still out there. Should fix the error mentioned in https://grist.slack.com/archives/C0234CPPXPA/p1652797247167719: ``` Traceback (most recent call last): File "/gristroot/grist/sandbox/grist/sandbox.py", line 103, in run ret = self._functions[fname](*args) File "/gristroot/grist/sandbox/grist/imports/register.py", line 11, in parse_excel return import_file(file_source) File "/gristroot/grist/sandbox/grist/imports/import_xls.py", line 20, in import_file parse_options, tables = parse_file(path) File "/gristroot/grist/sandbox/grist/imports/import_xls.py", line 26, in parse_file return parse_open_file(f) File "/gristroot/grist/sandbox/grist/imports/import_xls.py", line 69, in parse_open_file table_data_with_types = parse_data.get_table_data(rows, len(headers)) File "/gristroot/grist/sandbox/grist/parse_data.py", line 215, in get_table_data row.extend([""] * missing_values) AttributeError: 'tuple' object has no attribute 'extend' ``` Test Plan: Existing tests. Haven't figured out how to reproduce the original error. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3434 --- sandbox/grist/imports/import_xls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox/grist/imports/import_xls.py b/sandbox/grist/imports/import_xls.py index 7acd5322..3c019c2f 100644 --- a/sandbox/grist/imports/import_xls.py +++ b/sandbox/grist/imports/import_xls.py @@ -41,7 +41,7 @@ def parse_open_file(file_obj): for sheet in workbook: table_name = sheet.title rows = [ - row + list(row) for row in sheet.iter_rows(values_only=True) # Exclude empty rows, i.e. rows with only empty values. # `if not any(row)` would be slightly faster, but would count `0` as empty.