Skip to content

Raise exception when field source is a built-in #6766

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

Merged
merged 1 commit into from
Jul 1, 2019

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented Jun 29, 2019

This resolves #6351 by raising an exception when a field's source is a built-in function type.

class MySerializer(serializers.Serializer):
    date = serializer.ReadOnlyField(source='timestamp.date')

Because built-in signatures cannot be inspected, serialization causes the method to be coerced into a string instead of being invoked. It would be nice if this could be fixed, however, the suggestion is fairly complicated and brittle and raising a helpful error should be Good Enough™.

cc @antwan

@rpkilby rpkilby added this to the 3.10 Release milestone Jun 29, 2019
@tomchristie
Copy link
Member

Nice piece of work, this. Looks all good to me.

@tomchristie tomchristie merged commit 7179ea9 into encode:master Jul 1, 2019
@rpkilby rpkilby deleted the simple-callable-builtins branch July 1, 2019 16:33
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Objects builtin methods are not called when passed in fields source
2 participants