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
Generating the OpenAPI schema using drf-spectacular prints this warning:
Warning [FooFileList > FooFileSerializer]: could not resolve field on model <class 'foo.models.FooFile'> with path "fname.size". This is likely a custom field that does some unknown magic. Maybe consider annotating the field/property? Defaulting to "string". (Exception: 'NoneType' object has no attribute '_meta')
I would like some kind of workaround, but I am not sure how one would use extend_schema_field here. For the time being, I am going to ignore the warning and use a post-processing hook to fix FooFile.properties.fsize.type.
Hi, you can do this serializers.ReadOnlyField(source="fname") but not "fname.size". We can navigate arbitrary chains of models/fields/properties, but not attributes of field.
We have a lot of navigation power in there, but even if we would have accessed size, we still could not know what type it is. It is dynamically added and a implementation detail of that specific model field.
There are a few ways to get there (e.g. typed property function on the model) with ReadOnlyField, but I would use a SerializerMethodField on the seriailzer. It is slightly more vebose, but it is clean and typed:
Describe the bug
I have a simple file server:
Generating the OpenAPI schema using drf-spectacular prints this warning:
To Reproduce
See https://github.com/jennydaman/spectacular-fsize-bug
Expected behavior
No warnings.
components.schemas.FooFile.properties.fsize.type
should benumber
.The text was updated successfully, but these errors were encountered: