You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When the model has one or more django.db.models.fields.files.ImageFieldFile fields and the _as_dict function is called an {AttributeError} 'NoneType' object has no attribute 'seek' is raised when the deepcopy line is executed.
I found a solution to the problem was to insert a check for the ImageFieldFile class in the _as_dict function and cast it to a string that returns the filename as shown below.
def _as_dict(self, check_relationship, include_primary_key=True):
...
if isinstance(field_value, ImageFieldFile):
# deepcopy of ImageFieldFile causes an AttributeError 'NoneType' object has no attribute 'seek'
field_value = str(field_value)
# Explanation of copy usage here :
# https://github.com/romgar/django-dirtyfields/commit/efd0286db8b874b5d6bd06c9e903b1a0c9cc6b00
all_field[field.name] = deepcopy(field_value)
...
As a temporary workaround, I derived a new class from DirtyFieldsMixin, copied the entire _as_dict function, and added in the code above. This is not great though as I'd prefer to call your existing code in case it changes in the future.
Environment (please complete the following information):
OS: Ubuntu/Zorin 16
Python version: 3.9.13
Django version: problem exists for 3.1.14 & 3.2.13
django-dirtyfields version: 1.8.1
The text was updated successfully, but these errors were encountered:
Tried to replicate the bug but was not able to (even with the same environment versions). Please see the code below for some of the testing I did. The test passed even without the IF check you outlined. Perhaps it would be of help if you're able to provide your usage of the ImageField to see where the issue is.
Describe the bug
When the model has one or more
django.db.models.fields.files.ImageFieldFile
fields and the_as_dict
function is called an{AttributeError} 'NoneType' object has no attribute 'seek'
is raised when the deepcopy line is executed.I found a solution to the problem was to insert a check for the ImageFieldFile class in the
_as_dict
function and cast it to a string that returns the filename as shown below.As a temporary workaround, I derived a new class from
DirtyFieldsMixin
, copied the entire_as_dict
function, and added in the code above. This is not great though as I'd prefer to call your existing code in case it changes in the future.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: