TGViewer
Находки в опенсорсе: Python Находки в опенсорсе: Python @opensource_findings_python · 1.06K subscribers
Post #376 147
🚀 New issue to wemake-services/django-modern-rest by @vyhuholl
📝 Seeded OpenAPI examples of `datetime` and `time` change with the current time (#1632)


What's wrong?

Found while working on #1629. With DMR_SETTINGS = {'openapi_examples_seed': 1} and the same PYTHONHASHSEED, examples of datetime and time fields are different on every run:

class _Event(msgspec.Struct):
created_at: dt.datetime
day: dt.date
at: dt.time
duration: dt.timedelta


class _EventController(Controller[MsgspecSerializer]):
def get(self) -> _Event:
raise NotImplementedError

Two runs 3 seconds apart, both with PYTHONHASHSEED=0:

02:18:43  {"created_at": "2000-10-08T03:39:12.378838", "day": "2025-09-16", "at": "18:36:00.366279", "duration": "P0D"}
02:18:46 {"created_at": "2000-10-08T03:39:16.378838", "day": "2025-09-16", "at": "18:36:03.421377", "duration": "P0D"}

polyfactory generates these with Faker, and Faker's defaults end at the current time: datetime uses date_time_between, which ends at "now", and time uses time_object, which picks a time between 1970 and now. The seed fixes the random part, but the range moves with the clock, so the value moves too. date uses date_this_decade, which ends at today, so it changes once a day.

So a schema with such fields is never the same on two runs, even though the seed_example_factory docstring says that seeding per build "keeps a schema reproducible on its own".

How it should be?

The same openapi_examples_seed should give the same examples at any time. _ExampleFactory in dmr/openapi/mappers/example.py can override get_provider_map() and give datetime, date and time fixed bounds instead of "now".

timedelta could get a range there too: its examples are always P0D now, because time_delta() without end_datetime starts and ends at "now".

Used versions

django-modern-rest 0.15.0, polyfactory 3.3.0, faker 40.39.0

Reproduced on c35128a.

OS information

macOS 27.0


#bug #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
More from @opensource_findings_python
  1. Sep 25, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 `Settings.throttling_al…
  2. Sep 25, 2026🚀 New issue to wemake-services/wemake-python-styleguide by @sobolevn 📝 Incorrect Jones c…
  3. Sep 25, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 `_validate_throttling`…
  4. Sep 24, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 Flaky `test_empty_valid…
  5. Sep 24, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 `CookieJWT[A]syncAuth`…
  6. Sep 23, 2026🚀 New issue to ag2ai/faststream by @IvanKirpichnikov 📝 Feature: Implementation of the `A…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →