Skip to content
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

Serializing "complex" field returns None instead of the value since 3.4 #4272

Closed
aaugustin opened this issue Jul 16, 2016 · 1 comment
Closed
Labels
Milestone

Comments

@aaugustin
Copy link
Contributor

aaugustin commented Jul 16, 2016

(Not a great title — I hope the description will clarify.)

Steps to reproduce

First: pip install django-phonenumber-field

With the following model and serializer:

from django.db.models import Model
from phonenumber_field.modelfields import PhoneNumberField
from rest_framework.serializers import ModelSerializer

class PhoneModel(Model):
    number = PhoneNumberField()

class PhoneSerializer(ModelSerializer):
    class Meta:
        model = PhoneModel
        fields = ['number']

Expected behavior

This test used to pass (until version 3.3.3):

def test_phone_serializer():
    phone = models.PhoneModel(number='+33610293847')
    data = models.PhoneSerializer(phone).data
    assert data['number'] == '+33610293847'

Actual behavior

The test fails (since version 3.4) with:

    def test_phone_serializer():
        phone = models.PhoneModel(number='+33610293847')
        data = models.PhoneSerializer(phone).data
>       assert data['number'] == '+33610293847'
E       assert None == '+33610293847'

Analysis

I bisected this regression to 9c996d7.

As far as I can tell, DRF used to get the string representation of the field and no longer does.

(Pdb) phone.number
PhoneNumber(country_code=33, national_number=610293847, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=1, preferred_domestic_carrier_code='')
(Pdb) str(phone.number)
'+33610293847'
@aaugustin aaugustin changed the title Serializing "complex" field fails since 3.4 Serializing "complex" field returns None instead of the value since 3.4 Jul 16, 2016
@aaugustin
Copy link
Contributor Author

aaugustin commented Jul 16, 2016

Actually you seem to be missing a return here: 9c996d7#diff-ce493f71b3679e91b72126c168670399R128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants