pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
193 stars 51 forks source link

Support for Pendulum #112

Closed theunkn0wn1 closed 9 months ago

theunkn0wn1 commented 1 year ago

Initial Checks

Description

Attempting to use datetime sources other than (and better than) stdlib results in errors under pydantic 2.0 This is a regression from 1.x

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'pendulum.datetime.DateTime'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

Example Code

from pydantic import BaseModel
from pendulum import DateTime

class Example(BaseModel):
    last_modified: DateTime

Python, Pydantic & OS Version

python -c "import pydantic.version; print(pydantic.version.version_info())"   
             pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=true
                 install path: /home/REDACTED/.cache/pypoetry/virtualenvs/REDACTED-XAw2sOhv-py3.10/lib/python3.10/site-packages/pydantic
               python version: 3.10.11 (main, Apr 20 2023, 14:14:57) [GCC 9.4.0]
                     platform: Linux-5.15.0-84-generic-x86_64-with-glibc2.35
             related packages: typing_extensions-4.8.0 pydantic-settings-2.0.
sydney-runkle commented 1 year ago

Hi @theunkn0wn1,

Thanks for reporting this. I think this might make sense as an addition to pydantic-extra-types. We'd certainly consider any PRs supporting this change šŸ‘.

theunkn0wn1 commented 10 months ago

@sydney-runkle opened a PR to add this to pydantic-extra-types.

sydney-runkle commented 10 months ago

@theunkn0wn1,

Fantastic! I'm going to move this issue over there :).

wholmen commented 6 months ago

Hi, would it be possible to add the Time object as well?

theunkn0wn1 commented 5 months ago

Hi, would it be possible to add the Time object as well?

probably, PRs are welcome.

akincan-kilic commented 3 weeks ago

Is pendulum.DateTime now supported? I'm not seeing a mention of it on the official docs. I also get the following error:

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'pendulum.datetime.DateTime'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

Here is the piece of code that triggers this on my Pydantic class:

import pendulum

created_at: Optional[pendulum.DateTime] = Field(default=None)

Setting arbitrary_types_allowed on the configuration fixes this issue.

class Config:
    arbitrary_types_allowed = True

I made sure that the pydantic-extra-types package is installed.

UPDATE: I was looking at 2.0 documentation and not the latest 2.9 docs. I see it now. Sorry for the confusion šŸ™