{"action":"opened","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2598","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2598/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2598/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2598/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2598","id":58821739,"number":2598,"title":"Silent skipping of read-only fields that throw exceptions: weird! unintentional?","user":{"login":"ezheidtmann","id":1178915,"avatar_url":"https://avatars.githubusercontent.com/u/1178915?v=3","gravatar_id":"","url":"https://api.github.com/users/ezheidtmann","html_url":"https://github.com/ezheidtmann","followers_url":"https://api.github.com/users/ezheidtmann/followers","following_url":"https://api.github.com/users/ezheidtmann/following{/other_user}","gists_url":"https://api.github.com/users/ezheidtmann/gists{/gist_id}","starred_url":"https://api.github.com/users/ezheidtmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezheidtmann/subscriptions","organizations_url":"https://api.github.com/users/ezheidtmann/orgs","repos_url":"https://api.github.com/users/ezheidtmann/repos","events_url":"https://api.github.com/users/ezheidtmann/events{/privacy}","received_events_url":"https://api.github.com/users/ezheidtmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-24T23:10:19Z","updated_at":"2015-02-24T23:10:19Z","closed_at":null,"body":"I have a serializer with some read-only fields which are populated by a method on the model. This worked great. Then I made a change elsewhere that broke my method. Now my fields don't show up. Instead, I would have expected the exception to reach the browser somehow -- a 500 error from DRF or from Django core.\r\n\r\nI discovered that DRF is swallowing the exception thrown inside my function (an `AttributeError`) and silently skipping the field. This is confusing to me and I don't understand how this is useful; in fact, it seems that the logic is appropriate for a de-serialization (i.e. create or update) but not for output.\r\n\r\nIf the current behavior is desired, what's the reasoning? And if so, can we add something to the guide about it, under [exception handling](http://www.django-rest-framework.org/api-guide/exceptions/)?\r\n\r\nFor context, here's my serializer:\r\n\r\n```python\r\nclass SectionSerializer(serializers.HyperlinkedModelSerializer):\r\n    route_count = serializers.IntegerField(source='get_route_count', read_only=True)\r\n```\r\n\r\nAnd here's the method on my model:\r\n\r\n```python\r\nclass Section(Versionable):\r\n    ...\r\n    def get_route_count(self):\r\n        if self.route_type == Section.RT_BOULDER:\r\n            return self.boulderroute_set.count()\r\n        elif self.route_type == Section.RT_SPORT:\r\n            return self.sportroute_set.count()\r\n```\r\n\r\n(My function `get_route_count` is broken because I removed the `.RT_*` constants in a refactor)\r\n\r\nAnd this is where my AttributeError is caught in `fields.py`:\r\n\r\n```python\r\nclass Field(object):\r\n    ...\r\n    def get_attribute(self, instance):\r\n        \"\"\"\r\n        Given the *outgoing* object instance, return the primitive value\r\n        that should be used for this field.\r\n        \"\"\"\r\n        try:\r\n            return get_attribute(instance, self.source_attrs)\r\n        except (KeyError, AttributeError) as exc:\r\n            if not self.required and self.default is empty:\r\n                raise SkipField()\r\n            msg = (\r\n                'Got {exc_type} when attempting to get a value for field '\r\n                '`{field}` on serializer `{serializer}`.\\nThe serializer '\r\n                'field might be named incorrectly and not match '\r\n                'any attribute or key on the `{instance}` instance.\\n'\r\n                'Original exception text was: {exc}.'.format(\r\n                    exc_type=type(exc).__name__,\r\n                    field=self.field_name,\r\n                    serializer=self.parent.__class__.__name__,\r\n                    instance=instance.__class__.__name__,\r\n                    exc=exc\r\n                )\r\n            )\r\n            raise type(exc)(msg)\r\n```\r\n\r\nThanks all!"}}