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

Linting error when using nested models with optional arguments #3710

Closed
3 tasks done
andrewmsaid opened this issue Jan 20, 2022 · 2 comments
Closed
3 tasks done

Linting error when using nested models with optional arguments #3710

andrewmsaid opened this issue Jan 20, 2022 · 2 comments
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@andrewmsaid
Copy link

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.9.0
pydantic compiled: True
    install path: /usr/local/lib/python3.9/site-packages/pydantic
python version: 3.9.9 (main, Nov 17 2021, 16:20:40)  [GCC 10.2.1 20210110]
    platform: Linux-5.10.76-linuxkit-x86_64-with-glibc2.31
optional deps. installed: ['email-validator', 'typing-extensions']

When setting one of a model's arguments as another model and the nested model only has optional arguments, linter throws an error saying "Arguments missing for parameters". Because the default is an empty object and the NestedModel has all objects, this would run fine, but still shows linting errors.

import pydantic
from typing import Optional


class NestedModel(pydantic.BaseModel):
    attribute_a: Optional[int]
    attribute_b: Optional[int]
    attribute_c: Optional[str]


class MainModel(pydantic.BaseModel):
    nested: NestedModel = pydantic.Field(default=NestedModel())

image

@blueridger
Copy link

The workaround I use is setting an explicit None default.

    attribute_a: Optional[int] = None

@samuelcolvin
Copy link
Member

That's correct and will be necessary at runtime in V2.

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

No branches or pull requests

3 participants