pydantic-extra-types icon indicating copy to clipboard operation
pydantic-extra-types copied to clipboard

pendulum_dt: type object 'DateTime' has no attribute 'instance'

Open agriffin-grow opened this issue 1 year ago • 4 comments

instance() appears to be a top level pendulum method and not available on DateTime directly

It looks like 1.5.1 is the last version that supported DateTime.instance, and this package depends on pendulum 3.0.0

agriffin-grow avatar Oct 30 '24 22:10 agriffin-grow

To reproduce:

from pydantic import BaseModel
from pydantic_extra_types.pendulum_dt import Date, DateTime

class WithDate(BaseModel):
    dt: DateTime

WithDate.model_validate({
    "dt": "2024-10-30T01:00:30"
})

output:

Traceback (most recent call last):
  File "<redacted>/foo.py", line 9, in <module>
    WithDate.model_validate({
  File "<redacted>/lib/python3.10/site-packages/pydantic/main.py", line 568, in model_validate
    return cls.__pydantic_validator__.validate_python(
  File "<redacted>/lib/python3.10/site-packages/pydantic_extra_types/pendulum_dt.py", line 85, in _validate
    return DateTime.instance(value)
AttributeError: type object 'DateTime' has no attribute 'instance'

agriffin-grow avatar Oct 30 '24 22:10 agriffin-grow

@agriffin-grow. I faced a similar problem. Actually, in my case, pendulum was still not updated to version >=3.

dasschnee avatar Oct 31 '24 14:10 dasschnee

Make sure you're installing this library with the pendulum extras, otherwise it won't enforce pendulum >= 3 (which has the instance method).

poetry add "pydantic-extra-types[pendulum]"

oakhan3 avatar Oct 31 '24 15:10 oakhan3

@samuelcolvin @yezz123 opened a pr for the readme if you think it would help

oakhan3 avatar Oct 31 '24 16:10 oakhan3