I use DRF and django-storages to upload files to a S3 bucket.
I can create from the admin or from a POST to the API endpoint any new entry with a file.
But for some reason, as soon as I try to update the instance (be it from the admin or from the API endpoint), I get a ValueError
that seems to indicate that DRF can't find the file.
But when I use Django's admin or shell, I see that the file has been correctly saved (FieldFile
on instance) and that the file has been saved in the bucket.
I don't override anything: not the admin forms, not the serializer's update method, not the view's retrieve method, etc.
I have no idea how that could even be possible.
Any suggestion?
I ended up finding the solution. Somewhere in my code one of the serializer's fields had a
to_representation()
method that was returning theinstance
instead of theinstance.url
. I hope that this will help anyone.