UnboundLocalError: local variable 'column_names_first_row' referenced before assignment
adiavt opened this issue · 2 comments
adiavt commented
I get this error message when trying to do export to xlsx file:
I'm using python 3.6.5 on windows 10 64bit
Request Method: | GET |
---|---|
http://192.168.1.154:8005/api/transaction/excel/taxi/?start=2019-12-30&end=2019-12-30&search= | |
2.2.4 | |
UnboundLocalError | |
local variable 'column_names_first_row' referenced before assignment | |
C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36\lib\site-packages\drf_renderer_xlsx\renderers.py in render, line 122 | |
C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36\python.exe | |
3.6.5 | |
['D:\Projects\Python\nguraharaitaxi-backend', 'C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36\python36.zip', 'C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36\DLLs', 'C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36\lib', 'C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36', 'C:\Users\WEBDEV-5\AppData\Local\Programs\Python\Python36\lib\site-packages'] | |
Sen, 30 Des 2019 17:23:42 +0800 |
adiavt commented
I already figured this out, the problem is when checking for columns name first row:
if isinstance(results, ReturnDict):
column_names_first_row = results
elif isinstance(results, ReturnList):
column_names_first_row = self._flatten(results[0])
Checking if the results
is dictionary
or list
did not work.
I've added this extra check:
elif type(results) is list:
column_names_first_row = self._flatten(results[0])
elif type(results) is dict:
column_names_first_row = results
maybe you can fix this issue and provide some more relevant data type checking, thanks.