Skip to content

Calling json() no longer calls dict() #3780

@andreyfedoseev

Description

@andreyfedoseev

According to the documentation:

Typically, .json() in turn calls .dict() and serialises its result.

This behavior has been changed in 1.9.0, and calling .json() doesn't call .dict() anymore.

I consider this a breaking change because it breaks a documented feature. Also, the documentation hasn't been updated to reflect this change.

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

1.9.0
import pydantic

class MyModel(pydantic.BaseModel):
    
    spam: int

    def dict(self, **kwargs):
        d = super().dict(**kwargs)
        d["ham"] = 2
        return d

MyModel(spam=1).json()

# expect to get: {"spam": 1, "ham": 2}
# actually get: {"spam": 1}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions