{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2418","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2418/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2418/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2418/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2418","id":54352819,"number":2418,"title":"Inherited serializers","user":{"login":"cambonf","id":1140704,"avatar_url":"https://avatars.githubusercontent.com/u/1140704?v=3","gravatar_id":"","url":"https://api.github.com/users/cambonf","html_url":"https://github.com/cambonf","followers_url":"https://api.github.com/users/cambonf/followers","following_url":"https://api.github.com/users/cambonf/following{/other_user}","gists_url":"https://api.github.com/users/cambonf/gists{/gist_id}","starred_url":"https://api.github.com/users/cambonf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cambonf/subscriptions","organizations_url":"https://api.github.com/users/cambonf/orgs","repos_url":"https://api.github.com/users/cambonf/repos","events_url":"https://api.github.com/users/cambonf/events{/privacy}","received_events_url":"https://api.github.com/users/cambonf/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/labels/Needs+further+review","name":"Needs further review","color":"c7def8"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones/18","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones/18/labels","id":929695,"number":18,"title":"3.0.4 Release","description":"","creator":{"login":"xordoquy","id":2340654,"avatar_url":"https://avatars.githubusercontent.com/u/2340654?v=3","gravatar_id":"","url":"https://api.github.com/users/xordoquy","html_url":"https://github.com/xordoquy","followers_url":"https://api.github.com/users/xordoquy/followers","following_url":"https://api.github.com/users/xordoquy/following{/other_user}","gists_url":"https://api.github.com/users/xordoquy/gists{/gist_id}","starred_url":"https://api.github.com/users/xordoquy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xordoquy/subscriptions","organizations_url":"https://api.github.com/users/xordoquy/orgs","repos_url":"https://api.github.com/users/xordoquy/repos","events_url":"https://api.github.com/users/xordoquy/events{/privacy}","received_events_url":"https://api.github.com/users/xordoquy/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":13,"state":"open","created_at":"2015-01-10T10:17:24Z","updated_at":"2015-01-21T09:44:40Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-01-14T17:45:05Z","updated_at":"2015-01-21T09:55:38Z","closed_at":"2015-01-21T09:44:40Z","body":"We recently upgraded to DRF 3.0 and noticed an important change of behaviour with the serializers.\r\n\r\nFor 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\r\n\r\n```python\r\n\r\nclass TestSerializer(serializers.ModelSerializer):\r\n    a = serializers.SerializerMethodField('get_a')\r\n\r\n    class Meta:\r\n        model = TestModel\r\n        fields = ['a', 'b', 'c']\r\n\r\n    def get_a(self, obj):\r\n        return 0\r\n\r\n\r\nclass TestSubSerializer(TestSerializer):\r\n    class Meta:\r\n        model = TestModel\r\n        fields = ['a']\r\n```\r\n\r\nThis is useful because we don't have to rewrite `get_a` for each subserializer.\r\n\r\nHowever this does not work in 3.0 because the `__new__`,` __init__` methods of `SerializerMetaclass` retrieve the `declared_fields` of the current serializer class, not of its parents.\r\nThe following classes (with real code obviously) throw this error : \r\n\r\n`ImproperlyConfigured: Field name 'a' is not valid for model ModelBase.`\r\n\r\nIt does so because `a = serializers.serializers.SerializerMethodField('get_a')` is declared in the parent class\r\n\r\nPerhaps we are doing something wrong and not using the serializers properly ?\r\n\r\nThank you for your answer"},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/70811055","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2418#issuecomment-70811055","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2418","id":70811055,"user":{"login":"cambonf","id":1140704,"avatar_url":"https://avatars.githubusercontent.com/u/1140704?v=3","gravatar_id":"","url":"https://api.github.com/users/cambonf","html_url":"https://github.com/cambonf","followers_url":"https://api.github.com/users/cambonf/followers","following_url":"https://api.github.com/users/cambonf/following{/other_user}","gists_url":"https://api.github.com/users/cambonf/gists{/gist_id}","starred_url":"https://api.github.com/users/cambonf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cambonf/subscriptions","organizations_url":"https://api.github.com/users/cambonf/orgs","repos_url":"https://api.github.com/users/cambonf/repos","events_url":"https://api.github.com/users/cambonf/events{/privacy}","received_events_url":"https://api.github.com/users/cambonf/received_events","type":"User","site_admin":false},"created_at":"2015-01-21T09:55:38Z","updated_at":"2015-01-21T09:55:38Z","body":"#2388 is the same issue, the workaround provided solved my problem.\r\n\r\nThank you !"}}