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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy