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

arbitrary_types_allowed does not propagate to the model which is created for a NamedTuple #4219

Closed
3 tasks done
rorybyrne opened this issue Jul 7, 2022 · 1 comment · Fixed by #4225
Closed
3 tasks done
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@rorybyrne
Copy link
Contributor

rorybyrne commented Jul 7, 2022

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

When using a NamedTuple as a field in a pydantic model, it cannot have arbitrary types - even if arbitrary_types_allowed is True on the model. I found that when create_model_from_namedtuple is called, config is not passed (but for TypedDict, it is passed).

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

             pydantic version: 1.9.1
            pydantic compiled: True
                 install path: /home/rory/lab/mres/task/co/.venv/lib/python3.9/site-packages/pydantic
               python version: 3.9.13 (main, May 27 2022, 11:07:19)  [GCC 12.1.0]
                     platform: Linux-5.18.7-arch1-1-x86_64-with-glibc2.35
     optional deps. installed: ['typing-extensions']
from typing import NamedTuple
import pydantic

class Foo:
    pass

class Bar(NamedTuple):
    foo: Foo

class MyModel(pydantic.BaseModel):
    bar: Bar

    class Config:
        arbitrary_types_allowed = True

image

@rorybyrne rorybyrne added the bug V1 Bug related to Pydantic V1.X label Jul 7, 2022
@rorybyrne
Copy link
Contributor Author

rorybyrne commented Jul 7, 2022

I could open a PR for this? Looks like a quick change here to pass config.

I made a fix here, can PR it if someone gives the green light (tests are passing)

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