Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
agriffin-grow opened this issue Oct 30, 2024 · 4 comments
Open

Comments

@agriffin-grow
Copy link

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
Copy link
Author

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'

@dasschnee
Copy link

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

@oakhan3
Copy link
Contributor

oakhan3 commented Oct 31, 2024

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 pushed a commit to oakhan3/pydantic-extra-types that referenced this issue Oct 31, 2024
@oakhan3
Copy link
Contributor

oakhan3 commented Oct 31, 2024

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

yezz123 added a commit that referenced this issue Jan 15, 2025
* Add additional installation information to README (#232)

* 📝 Update README.md

---------

Co-authored-by: Omar Ali Khan <[email protected]>
Co-authored-by: Yasser Tahiri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants