[Fixed]-Django import export – Unable to import model with BinaryField

3👍

Sadly this seems to be a problem with django-import-export module.

In Python 2.7+ and 3.5.2+, pickling memoryview objects, is permitted. Try the following code just to confirm that:

import pickle

test = memoryview(b'abc')
test.__reduce__()

The above will raise the following error:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle memoryview objects

Apparently, in line 451 of django-import-export (version 0.6), the BinaryField is passed as a memoryview object to

original = deepcopy(instance)

which causes the error (instance contains the BinaryField as a memoryview object).
In the current version (1.0.0) this happens in line 446.

The instance retrieved/generated by the instance_loader of the module doesn’t take into consideration the BinaryField.

You should probably open a ticket at django-import-export about this.

0👍

have you added binary_field in ABCModelForm ? If yes, then it is creating issue because It is not possible to include a BinaryField in a ModelForm. For reference : binaryfield

0👍

Maybe passing the actual array instead of the memory view can solve your problem. If you want to execute a function in parallel, all of it parameters have to be picklable if i recall correctly. At least that is the case with python multiprocessing. So you could pass the array to the function and create the memoryview inside your function.

reference: moreinfo

Leave a comment