jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/376561 )
Change subject: output: Fallback to write_string when some error occur in write
for xlsx
..
output: Fallback to write_string when some error occur in write for xlsx
Type specific errors, eg. urls longer than 255 characters, return a
value usually < -1 on write(). We fallback to basic string, without
type conversion, with write_string(), if the given cell is a string.
Bug: T175285
Change-Id: Ie4ed21e646a8df7d14edd8161a82c89aae4c3b65
---
M quarry/web/output.py
1 file changed, 10 insertions(+), 2 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/quarry/web/output.py b/quarry/web/output.py
index 10ce6e4..234b991 100644
--- a/quarry/web/output.py
+++ b/quarry/web/output.py
@@ -116,8 +116,16 @@
# somehow not UTF-8, we replace them to not get an UnicodeError
# from within xlsxwriter.
cell = cell.decode('utf-8', 'replace')
-# TODO: write_row?
-worksheet.write(row_num, col_num, cell)
+# T175285: xlsx can't do urls longer than 255 chars.
+# We first try writing it with write(), if it fails due to
+# type-specific errors (return code < -1; 0 is success and -1 is
+# generic row/col dimension error), we use write_string to force
+# writing as string type, which has a max of 32767 chars.
+# This only works when cell is a string, however; so only string
+# will use fallback.
+if (worksheet.write(row_num, col_num, cell) < -1 and
+isinstance(cell, basestring)):
+worksheet.write_string(row_num, col_num, cell)
workbook.close()
output.seek(0)
--
To view, visit https://gerrit.wikimedia.org/r/376561
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie4ed21e646a8df7d14edd8161a82c89aae4c3b65
Gerrit-PatchSet: 2
Gerrit-Project: analytics/quarry/web
Gerrit-Branch: master
Gerrit-Owner: Zhuyifei1999
Gerrit-Reviewer: Zhuyifei1999
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits