Workaround Django error on model delete due to empty file field w/Thumbnailer

StackOverflow https://stackoverflow.com/questions/16679880

  •  30-05-2022
  •  | 
  •  

Pergunta

I have a model with an EasyThumbnailer file field, using Boto storage and UnDelete, and some instances of that model have an empty file field that prevents me from deleting them:

python/lib/python2.7/site-packages/django/db/models/fields/files.pyc in _require_file(self)
     39     def _require_file(self):
     40         if not self:
---> 41             raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
     42 
     43     def _get_file(self):

ValueError: The 'image' attribute has no file associated with it.

I get this error when I try to delete from within the shell or from the website, and I don't know how to work around it or remove whatever protection is causing this to result in an error.

I don't need a clean solution, as this code base is not long for this world, just something that works.

Foi útil?

Solução

model.delete(trash=False)

Turns out this is due to interactions between "trashable" and the empty file field, so this skips those interactions.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top