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

Signature of inherited dataclass does not include subclass field #7906

Closed
1 task done
shinaji opened this issue Oct 24, 2023 · 4 comments · Fixed by #7925
Closed
1 task done

Signature of inherited dataclass does not include subclass field #7906

shinaji opened this issue Oct 24, 2023 · 4 comments · Fixed by #7925
Assignees
Labels
bug V2 Bug related to Pydantic V2 good first issue

Comments

@shinaji
Copy link

shinaji commented Oct 24, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Hello, I found that the signature of inherited dataclass seems to have only its superclass fields. Is this expected behavior at pydantic v2? Due to this, FastAPI seems to ignore the subclass field value.

Example Code

from pydantic.dataclasses import dataclass

@dataclass
class A:
    a: int

@dataclass
class B(A):
    b: int

# In [4]: B.__signature__
# Out[4]: <Signature (a: int) -> None>  # "b: int" is missing

Python, Pydantic & OS Version

pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=false
               python version: 3.9.13 (main, Sep 17 2022, 22:53:18)  [Clang 14.0.0 (clang-1400.0.29.102)]
                     platform: macOS-13.6-arm64-arm-64bit
             related packages: email-validator-2.0.0.post2 pydantic-extra-types-2.1.0 mypy-1.3.0 typing_extensions-4.8.0 fastapi-0.104.0 pydantic-settings-2.0.3
@shinaji shinaji added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Oct 24, 2023
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Oct 24, 2023
@sydney-runkle sydney-runkle self-assigned this Oct 24, 2023
@sydney-runkle
Copy link
Member

Hi @shinaji,

Thanks for reporting this. Looks like a bug with the pydantic dataclass signature generation. I've marked this with the good first issue tag, if anyone wants to help!

@sydney-runkle
Copy link
Member

This should be helpful:

def generate_dataclass_signature(cls: type[StandardDataclass]) -> Signature:
"""Generate signature for a pydantic dataclass.
This implementation assumes we do not support custom `__init__`, which is currently true for pydantic dataclasses.
If we change this eventually, we should make this function's logic more closely mirror that from
`pydantic._internal._model_construction.generate_model_signature`.

@howsunjow
Copy link
Contributor

@sydney-runkle I've contributed a fix in a PR. Not sure how exactly to assign a reviewer though.

@sydney-runkle
Copy link
Member

@howsunjow awesome, thanks! I just submitted a review. Thanks for your contribution 👍 ⭐

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 good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants