Skip to content

When OneToOneField are primary_key, this field in DRF 3.4 will always be null !! #4288

@mrgaolei

Description

@mrgaolei

Model Define:

class Goods(models.Model):
    xxx = models.CharField("xxx", max_length=100)

class GoodsMeta(models.Model):
    goods = models.OneToOneField(Goods, primary_key=True)
    content = models.TextField()

Serializer Define is very simple:

class GoodsMetaSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsMeta

In DRF 3.3.3, everything OK, json output:

{["goods":1, "content":"xxx"]}

But in DRF 3.4, the OneToOneField with primary_key always be null:

{["goods":null, "content":"xxx"]}

Why this happened? Is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions