DRF's serializer's SerializerMethodField are shown in .get_fields() #9537
Unanswered
Teut2711
asked this question in
Ideas & Suggestions
Replies: 1 comment 1 reply
-
For your use case I think you want to either inspect read_only or inspect the type. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I wanted to check if the current behavior I'm observing is expected.
Currently, calling .get_fields() on an instance of a serializer returns all fields, including computed fields such as SerializerMethodField. In my use case, I'm parsing a complex text file and using serializers for validation, among other things. After parsing, I end up with a list of CSV rows, which I feed one by one into the serializer.
My expectation is that I should be able to create a dictionary from .get_fields().keys() and the row containing the data. Ideally, only the non-computed fields should be returned. After mapping the data and passing it to the serializer for validation, the computed fields would then be generated.
Is this behavior intentional, or is there a recommended approach to exclude computed fields when calling .get_fields()?
Beta Was this translation helpful? Give feedback.
All reactions