def get_attribute(self, instance):
        if self.use_pk_only_optimization() and self.source_attrs:
            # Optimized case, return a mock object only containing the pk attribute.
            try:
                instance = get_attribute(instance, self.source_attrs[:-1])
                value = instance.serializable_value(self.source_attrs[-1])
                if is_simple_callable(value):
                    # Handle edge case where the relationship `source` argument
                    # points to a `get_relationship()` method on the model
                    value = value().pk
                return PKOnlyObject(pk=value)
            except __HOLE__:
                pass

        # Standard case, return the object instance.
        return get_attribute(instance, self.source_attrs)
dataset/ETHPy150Open tomchristie/django-rest-framework/rest_framework/relations.py/RelatedField.get_attribute