-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inherited serializers #2418
Comments
Either related to, or duplicate of #2388 - haven't determined which yet. |
Copied your example as a test case, but does not reproduce...
Closing this off, but still continuing with the valid #2388. Can reopen this is a failing test case is supplied as a pull request, or the question is otherwise clarified. |
#2388 is the same issue, the workaround provided solved my problem. Thank you ! |
I came up with the exact same problem, |
We recently upgraded to DRF 3.0 and noticed an important change of behaviour with the serializers.
For performance reasons, we implemented serializers in DRF 2.X that inherited each other to stay as DRY as possible. For one type of model we sometimes have up to 5/6 sub serializers
This is useful because we don't have to rewrite
get_a
for each subserializer.However this does not work in 3.0 because the
__new__
,__init__
methods ofSerializerMetaclass
retrieve thedeclared_fields
of the current serializer class, not of its parents.The following classes (with real code obviously) throw this error :
ImproperlyConfigured: Field name 'a' is not valid for model ModelBase.
It does so because
a = serializers.serializers.SerializerMethodField('get_a')
is declared in the parent classPerhaps we are doing something wrong and not using the serializers properly ?
Thank you for your answer
The text was updated successfully, but these errors were encountered: