Skip to content

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

@rorybyrne

Description

@rorybyrne

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

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