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

model_post_init from BaseModel appears in the rendered documentation #198

Open
helgee opened this issue Jan 26, 2024 · 5 comments
Open

model_post_init from BaseModel appears in the rendered documentation #198

helgee opened this issue Jan 26, 2024 · 5 comments
Labels
question Further information is requested

Comments

@helgee
Copy link

helgee commented Jan 26, 2024

See screenshot. This is not supposed to happen, right?

grafik
@helgee
Copy link
Author

helgee commented Jan 29, 2024

Here is an MWE.

The problem appears when I provide a custom __init__ for the model (like shown here).

class Test(BaseModel):
    field: str = Field(description="My field")
    _field: str = PrivateAttr()
    
    def __init__(self, **data):
        super().__init__(**data)
        self._field = self.field

@helgee
Copy link
Author

helgee commented Jan 29, 2024

Workaround: Add a :exclude-members: model_post_init directive.

@j-carson
Copy link
Contributor

You can also exclude everything on BaseModel with the :inherited-members: BaseModel directive

@mansenfranzen
Copy link
Owner

@helgee Have you tried @j-carson solution and is it feasible for you?

@mansenfranzen mansenfranzen added enhancement New feature or request question Further information is requested and removed enhancement New feature or request labels Mar 14, 2024
@j-carson
Copy link
Contributor

@mansenfranzen I suggested that workaround since my last PR had been hanging out for so long without response.

Pydantic 2 has a documented naming convention that the items it adds via the BaseModel class will all start with "model_" -- it seems like the better long-term solution would be an autodoc pydantic option to bulk-drop these attributes rather than a hardcoded list in the autodocumenter's __init__ method since the exact list has changed over time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants