Why does FileField.to_representation return null for non-null values? #9958
Replies: 2 comments
-
|
My guess: from a REST API perspective or by being framework/language agnostic (ignoring Django's choice), the |
Beta Was this translation helpful? Give feedback.
-
|
Here's a clearer example that I think shows it's not related to Django: The serializer converts an empty string to null. Not only is this undocumented, but if you generate a schema with drf-spectacular, the schema does not allow null, so your consumers will receive an unexpected null value. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Django's
FileField(null=False, blank=True), stores""in the DB when there's no file. DRF currently serializes this to null due to a falsy check in to_representation:This is wrong because the field has null/allow_null=False. Is this intentional or would a PR fixing this be welcome?
Beta Was this translation helpful? Give feedback.
All reactions