-
-
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
allow overriding of fields in subclassed serializers. #1053
Conversation
Thanks! |
I added some tests for various cases, which now pass. My initial fix actually broke things but that's fixed now. |
|
||
# if there are fields in both base_fields and fields, SortedDict | ||
# uses the *last* one defined. So fields needs to go last. | ||
return SortedDict(base_fields + fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still struggling to review. C'mon brain. :-/
One possible issue is that this allows overriding Serializers and gets the fields right, but doesn't allow overriding of |
You're saying that... if I define a I haven't really used |
Seems like it should be overridden via the normal class mro; I don't see any stuff in the metaclass that messes with If you want to inherit the
That's ... slightly unexpected since Django doesn't quite do it that way for models (some options get inherited automatically, others don't). But that seems unrelated to this issue to me. |
Actually, that Meta overriding thing is consistent with Django's forms: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#form-inheritance (just not consistent with models) |
We've made the decision to close of all currently open serializer tickets, pending the 3.0 release. The 3.0 release will involve a major redesign and improvement of the current serializer implementation and should invalidate the large majority of these outstanding tickets. We will be reviewing the closed tickets prior to the 3.0 launch and try to ensure that we have fully covered any long-standing issues, and adequately dealt with the outstanding problems. If your issue does not appear to be addressed by the upcoming 3.0 release please do comment on your ticket with the current status, and we can reopen any valid tickets as required. In particular, if your ticket represents a long-standing or fundamental problem please do make sure to follow the mailing list and review any 3.0 pre-release candidates where possible. Note that you can review the closed tickets with the following searches: Serializer tickets: https://github.com/tomchristie/django-rest-framework/issues?q=label%3ASerializers Many thanks for your understanding and here's looking forward to a new and improved version, and a cleaner more actionable issue list. All the best, Tom |
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
This is an updated version of encode#1053 applied to current master.
Django allows overriding of fields (on forms, not on models), so it seems DRF could too.
It mostly works; the problem is the order the fields get passed to the SortedDict causes them to be "un-overridden" by the superclass fields again.
I will add tests, if this is otherwise OK.