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

inherit_config overwrites json_encoders from class creation arguments #2521

Closed
3 tasks done
layday opened this issue Mar 14, 2021 · 0 comments · Fixed by #2523
Closed
3 tasks done

inherit_config overwrites json_encoders from class creation arguments #2521

layday opened this issue Mar 14, 2021 · 0 comments · Fixed by #2523
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@layday
Copy link
Contributor

layday commented Mar 14, 2021

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())":

             pydantic version: 1.8.1
            pydantic compiled: False
                 install path: [...]/lib/python3.9/site-packages/pydantic
               python version: 3.9.2 (default, Feb 21 2021, 06:38:26)  [Clang 7.1.0 (tags/RELEASE_710/final)]
                     platform: macOS-10.14.6-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
import pydantic

class Foo(pydantic.BaseModel):
    class Config:
        json_encoders = {int: str}

print('Foo json_encoders:', Foo.__config__.json_encoders)


class Bar(pydantic.BaseModel, json_encoders={int: str}):
    pass

print('Bar json_encoders:', Bar.__config__.json_encoders)

Output:

Foo json_encoders: {<class 'int'>: <class 'str'>}
Bar json_encoders: {}

Culprit:

https://github.com/samuelcolvin/pydantic/blob/62bb2ad4921016df51abf3922c3fe51113b08939/pydantic/main.py#L184-L187

@layday layday added the bug V1 Bug related to Pydantic V1.X label Mar 14, 2021
samuelcolvin pushed a commit that referenced this issue May 11, 2021
* Test that `json_encoders` are respected from class kwargs

* Allow passing `json_encoders` in class kwargs

Fixes #2521.
samuelcolvin pushed a commit that referenced this issue May 11, 2021
* Test that `json_encoders` are respected from class kwargs

* Allow passing `json_encoders` in class kwargs

Fixes #2521.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant