pydantic / pydantic-extra-types

Extra Pydantic types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Date type does not decompose correctly

prutheus opened this issue · comments

I have a model definition:

from pydantic_extra_types.pendulum_dt import Date

class TypeValuePair(BaseModel):
    """
    type: value
    """

    type: str = Field(...)
    value: str = Field(...)

    class Config:
        """
        config
        """

        populate_by_name = True
        json_schema_extra = {
            "example": {"type": "Subject Area", "value": "Drainage Sewage"}
        }

class Transaction(BaseModel):
    """
    transac, note, date
    """

    transac: TypeValuePair = Field(...)
    note: TypeValuePair = Field(...)
    date: Date = Field(...)

    class Config:
        """
        config
        """

        populate_by_name = True
        arbitrary_types_allowed = True
        json_schema_extra = {
            "example": {
                "transac": {
                    "type": "terminologyManagementTransactions",
                    "value": "origination",
                },
                "note": {"type": "responsibility", "value": "joanna.schroer"},
                "date": "2015-03-09",
            }
        }

When I want to create an object of this model, it is not correctly decomposed to the pendulum Date type:

Transaction(transac=ml.TypeValuePair(type="", value=""), note=ml.TypeValuePair(type="", value=""), date="2015-03-09")

Returns:

Transaction(transac=TypeValuePair(type='', value=''), note=TypeValuePair(type='', value=''), date=datetime.date(2015, 3, 9))

Where the date parameter is type datetime.date instead of pendulum.Date. If I use DateTime instead of Date it works fine. What is the issue?

commented

probably fixed here #184