litestar icon indicating copy to clipboard operation
litestar copied to clipboard

Tests: AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)

Open benjamin-kirkbride opened this issue 1 year ago • 12 comments

Description

I just installed Litestar from the repo for dev purposes following the instructions found here.

I ran the tests with make test and got the following:

FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue2] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue3] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue0] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue1] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_schema.py::test_annotated_types - assert datetime.date(1979, 12, 31) == datetime.date(1980, 1, 1)

Litestar Version

2.0.0

Platform

  • [X] Linux
  • [ ] Mac
  • [ ] Windows
  • [ ] Other (Please specify in the description above)

Funding

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
Fund with Polar

benjamin-kirkbride avatar Sep 10 '23 15:09 benjamin-kirkbride

Can you check if in the file tests/unit/test_openapi/utils.py if you make the following change the tests pass?


from datetime import datetime, timezone
today = datetime.now(timezone.utc).date().today()
constrained_dates = [
    condate(gt=today - timedelta(days=10), lt=today + timedelta(days=100)),
    condate(ge=today - timedelta(days=10), le=today + timedelta(days=100)),
    condate(gt=today - timedelta(days=10), lt=today + timedelta(days=100)),
    condate(ge=today - timedelta(days=10), le=today + timedelta(days=100)),
]

Alc-Alc avatar Sep 10 '23 15:09 Alc-Alc

@Alc-Alc

FAILED
tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue2] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue1] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue0] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_constrained_fields.py::test_create_date_constrained_field_schema_pydantic_v1[ConstrainedDateValue3] - AssertionError: assert datetime.date(2023, 8, 30) == datetime.date(2023, 8, 31)
FAILED tests/unit/test_openapi/test_schema.py::test_annotated_types - assert datetime.date(1979, 12, 31) == datetime.date(1980, 1, 1)

Seemingly no change

benjamin-kirkbride avatar Sep 10 '23 15:09 benjamin-kirkbride

The issue persists if I replace the time delta of 10 days to 11, or 2 days. So it doesn't seem to be an issue due to it being the 10th.

benjamin-kirkbride avatar Sep 10 '23 16:09 benjamin-kirkbride

Exact same thing again today. Curious if anyone else has this issue?

benjamin-kirkbride avatar Sep 12 '23 02:09 benjamin-kirkbride

Exact same thing again today. Curious if anyone else has this issue?

No. Are you on win?

Goldziher avatar Sep 12 '23 04:09 Goldziher

Linux. Debian specifically

On Tue, Sep 12, 2023, 12:41 AM Goldziher @.***> wrote:

Exact same thing again today. Curious if anyone else has this issue?

No. Are you on win?

— Reply to this email directly, view it on GitHub https://github.com/litestar-org/litestar/issues/2293#issuecomment-1714952643, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZXWBXWPO6Q67ICRBNLU73XZ7RWPANCNFSM6AAAAAA4SH3RJY . You are receiving this because you authored the thread.Message ID: @.***>

benjamin-kirkbride avatar Sep 12 '23 13:09 benjamin-kirkbride

@benjamin-kirkbride Do you know why pydantic v1 was installed instead of pydantic v2? By default, pydantic v2 should be installed when doing poetry install --extras full.

guacs avatar Sep 13 '23 14:09 guacs

Same behavior on macOS. My initial impression was that this was related to timezones, so I tried replacing a couple of .now() to utcnow(), and some other today() logic, but found the same errors, haven't tried playing around with different dependencies though.

ccrvlh avatar Sep 18 '23 04:09 ccrvlh

@ccrvlh have you explicitly installed pydantic V1 to replicate the issue? I can't replicate.

peterschutt avatar Sep 18 '23 05:09 peterschutt

No, I just followed the contributing guide, no manual intervention on dependencies (checked today and Pydantic v2 is installed). I'll try rebuilding the environment tomorrow. I got the same errors both on an M1 and Intel macOS.

ccrvlh avatar Sep 18 '23 05:09 ccrvlh

And are the failing tests the pydantic V1 tests, such as in OP?

peterschutt avatar Sep 18 '23 05:09 peterschutt

Yeah exactly the same tests as the original post fails.

ccrvlh avatar Sep 18 '23 06:09 ccrvlh