Skip to content

Commit c945158

Browse files
committed
avoid django datetime error
1 parent c3b9945 commit c945158

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
RELEASE_TYPE: patch
22

33
This patch improves shrinking in cases involving 'slips' from one strategy to another. Highly composite strategies are the most likely to benefit from this change.
4+
5+
This patch also reduces the range of :class:`python:datetime.datetime` generated by :func:`~hypothesis.extra.django.from_model` in order to avoid https://code.djangoproject.com/ticket/35683.

hypothesis-python/src/hypothesis/extra/django/_fields.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import re
1212
import string
13-
from datetime import timedelta
13+
from datetime import datetime, timedelta
1414
from decimal import Decimal
1515
from functools import lru_cache
1616
from typing import Any, Callable, Dict, Type, TypeVar, Union
@@ -115,7 +115,12 @@ def inner(func):
115115
@register_for(df.DateTimeField)
116116
def _for_datetime(field):
117117
if getattr(django.conf.settings, "USE_TZ", False):
118-
return st.datetimes(timezones=timezones())
118+
# avoid https://code.djangoproject.com/ticket/35683
119+
return st.datetimes(
120+
min_value=datetime.min + timedelta(days=1),
121+
max_value=datetime.max - timedelta(days=1),
122+
timezones=timezones(),
123+
)
119124
return st.datetimes()
120125

121126

0 commit comments

Comments
 (0)