Skip to content

Commit 5e51951

Browse files
committed
Add support for using timezone aware datetime objects with Github
provider.
1 parent 3372375 commit 5e51951

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

codespeed/commits/github.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import isodate
2121
from django.core.cache import cache
22+
from django.conf import settings
2223

2324
from .exceptions import CommitLogError
2425

@@ -91,11 +92,13 @@ def retrieve_revision(commit_id, username, project, revision=None):
9192
if revision:
9293
# Overwrite any existing data we might have for this revision since
9394
# we never want our records to be out of sync with the actual VCS:
94-
95-
# We need to convert the timezone-aware date to a naive (i.e.
96-
# timezone-less) date in UTC to avoid killing MySQL:
97-
revision.date = date.astimezone(
98-
isodate.tzinfo.Utc()).replace(tzinfo=None)
95+
if not getattr(settings, 'USE_TZ_AWARE_DATES', False):
96+
# We need to convert the timezone-aware date to a naive (i.e.
97+
# timezone-less) date in UTC to avoid killing MySQL:
98+
logger.debug('USE_TZ_AWARE_DATES setting is set to False, '
99+
'converting datetime object to a naive one')
100+
revision.date = date.astimezone(
101+
isodate.tzinfo.Utc()).replace(tzinfo=None)
99102
revision.author = commit_json['author']['name']
100103
revision.message = commit_json['message']
101104
revision.full_clean()

codespeed/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@
8383

8484
ALLOW_ANONYMOUS_POST = True # Whether anonymous users can post results
8585
REQUIRE_SECURE_AUTH = True # Whether auth needs to be over a secure channel
86+
87+
US_TZ_AWARE_DATES = False # True to use timezone aware datetime objects with Github provider.
88+
# NOTE: Some database backends may not support tz aware dates.

0 commit comments

Comments
 (0)