A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pydantic/pydantic/issues/655 below:

add private attribute · Issue #655 · pydantic/pydantic · GitHub

I have a use case that I'd to add an attribute when initialising the instance which is not part of the model, thus should not be validated. Is that possible?

Here's a practical example:

from pydantic import BaseModel
from datetime import datetime

class Test(BaseModel):
    a: int

class TestExtra(BaseModel):
    a: int

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._processed_at = datetime.utcnow()

test = {"a": 1}
Test(**test)
TestExtra(**test)  # ValueError: "TestExtra" object has no field "_processed_at"

tpvasconcelos, yajo, syenchuk, vbarsegyan-fn, ramast and 7 more


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4