pendulum_dt: type object 'DateTime' has no attribute 'instance'
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
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. I faced a similar problem. Actually, in my case, pendulum was still not updated to version >=3.
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]"
@samuelcolvin @yezz123 opened a pr for the readme if you think it would help