Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python 3.5 -> 3.6 Tablib TypeError: cell() missing 1 required positional argument: 'column'

Migrating from python 3.5 to 3.6, my unit tests reveal a problem with django-import-export & tablib:

TypeError: cell() missing 1 required positional argument: 'column'

File "<path>/lib/python3.6/site-packages/tablib/formats/_xlsx.py", line 122, in dset_sheet
    cell = ws.cell('%s%s' % (col_idx, row_number))
    TypeError: cell() missing 1 required positional argument: 'column'

The line in tablib:

    cell = ws.cell('%s%s' % (col_idx, row_number))

So indeed, there is no argument for the column

My view code:

my_resource = MyModelResource(queryset=my_queryset)
dataset = my_resource.export()
response = HttpResponse(dataset.xlsx, content_type='application/vnd.ms-excel')

This works fine in python3.5 but fails under 3.6

requirements.txt:

...
tablib==0.12.1
django-import-export==0.7.0
Django==1.11.7
...
like image 942
Davy Avatar asked Feb 03 '18 13:02

Davy


1 Answers

This has nothing to do with Python 3.5 or 3.6. You have a newer openpyxl version installed with your 3.6 installation compared to your 3.5 setup.

The version you have installed with 3.6 has removed the deprecated coordinate parameter from worksheet.cell() method and made the row and column mandatory arguments. This is part of version 2.5.0b1, released on 2018-01-19 (two weeks ago):

Major Changes

worksheet.cell() no longer accepts a coordinate parameter. The syntax is now ws.cell(row, column, value=None)

The tablib library has not yet adjusted to this change. The code should just pass in the column and row numbers directly:

cell = ws.cell(row=row_number, column=col_idx)

Using keyword arguments would ensure compatibility all the way back to 1.1.0 (the release that added support for the column and row parameters, released in 2010).

In the meantime, you can downgrade your openpyxl installation to version 2.4.9, the last release without those changes.

Also see issue #324 in the tablib project repository.

like image 60
Martijn Pieters Avatar answered Oct 23 '22 22:10

Martijn Pieters