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

FutureDatetime accepts years 1000-1599 #8570

Open
1 task done
Zer0x00 opened this issue Jan 17, 2024 · 6 comments · May be fixed by pydantic/speedate#55
Open
1 task done

FutureDatetime accepts years 1000-1599 #8570

Zer0x00 opened this issue Jan 17, 2024 · 6 comments · May be fixed by pydantic/speedate#55
Assignees
Labels
bug V2 Bug related to Pydantic V2 help wanted Pull Request welcome

Comments

@Zer0x00
Copy link

Zer0x00 commented Jan 17, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

FutureDatetime should only accept datetime values that are in the future.

However, when I pass a year between 1000 and 1599 it gets accepted.

Example Code

from pydantic import BaseModel, FutureDatetime


class Model(BaseModel):
    dt: FutureDatetime


m = Model(dt="1500-01-01T00:00:00+00:00")

print(m.model_dump())

Python, Pydantic & OS Version

pydantic version: 2.5.3
        pydantic-core version: 2.14.6
          pydantic-core build: profile=release pgo=false
                 install path: /home/dev/.local/lib/python3.12/site-packages/pydantic
               python version: 3.12.0 (main, Nov  1 2023, 09:49:28) [GCC 10.2.1 20210110]
                     platform: Linux-6.5.13-orbstack-00121-ge428743e4e98-aarch64-with-glibc2.31
             related packages: typing_extensions-4.9.0 pydantic-settings-2.1.0 fastapi-0.109.0
@Zer0x00 Zer0x00 added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Jan 17, 2024
@sydney-runkle sydney-runkle added help wanted Pull Request welcome and removed pending Awaiting a response / confirmation labels Jan 17, 2024
@sydney-runkle
Copy link
Member

sydney-runkle commented Jan 17, 2024

@Zer0x00,

Indeed looks like a bug. PRs welcome with a fix! Thanks for reporting this. My hunch is that this might be a fix for pydantic-core or speedate.

@sydney-runkle
Copy link
Member

Ah yes, the fix will be in speedate, see this error:

thread '<unnamed>' panicked at /Users/programming/.cargo/registry/src/index.crates.io-6f17d22bba15001f/speedate-0.13.0/src/date.rs:219:20:
attempt to subtract with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/programming/pydantic_work/pydantic/test.py", line 8, in <module>
    m = Model(dt="1500-01-01T00:00:00+00:00")
  File "/Users/programming/pydantic_work/pydantic/pydantic/main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pyo3_runtime.PanicException: attempt to subtract with overflow

@StrawHatDrag0n
Copy link
Contributor

@sydney-runkle I would like to work on this! Can you please assign this to me ?

@samuelcolvin
Copy link
Member

Done.

@sydney-runkle
Copy link
Member

@StrawHatDrag0n,

I think the fix to be implemented here is that we shouldn't have a Panic Exception, but rather an informative error that dates prior to 1600 can't be handled. The changes for this will be in speedate.

@davidhewitt
Copy link
Contributor

I think we can do better; pydantic/speedate#55 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 help wanted Pull Request welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants