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

Non-standard characters in field names can lead to error when initializing a model using double star and a dictionary #9345

Open
1 task done
luizfelippesr opened this issue Apr 29, 2024 · 1 comment
Labels
bug V2 Bug related to Pydantic V2

Comments

@luizfelippesr
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

When some special characters are used as field names, initializing a model using a dictionary leads to a validation error.

Example Code

import pydantic

class Example(pydantic.BaseModel):
    width_µm: float

my_data = {'width_µm': 33}

# The following works fine
this_works = Example(width_µm = 42)

# However, this does not work
this_does_not_work = Example(**my_data)

Python, Pydantic & OS Version

pydantic version: 2.7.1
        pydantic-core version: 2.18.2
          pydantic-core build: profile=release pgo=false
                 install path: /home/lfsr/miniforge3/envs/ds/lib/python3.12/site-packages/pydantic
               python version: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]
                     platform: Linux-6.5.0-28-generic-x86_64-with-glibc2.38
             related packages: typing_extensions-4.10.0
                       commit: unknown
@luizfelippesr luizfelippesr added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 29, 2024
@sydney-runkle
Copy link
Member

@luizfelippesr,

Thanks for reporting. I can indeed confirm that this is an issue. PRs welcome with a fix, though I don't think this is high priority.

@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2
Projects
None yet
Development

No branches or pull requests

2 participants