Skip to content

Commit e89a614

Browse files
authored
Merge pull request tobami#279 from Kami/support_tz_aware_datetime_objects
Support timezone aware datetime objects with Github provider
2 parents 33da18a + 7a0091d commit e89a614

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

codespeed/commits/github.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import json
2121

2222
import isodate
23-
from django.conf import settings
2423
from django.core.cache import cache
24+
from django.conf import settings
2525

2626
from .exceptions import CommitLogError
2727

@@ -103,11 +103,13 @@ def retrieve_revision(commit_id, username, project, revision=None):
103103
if revision:
104104
# Overwrite any existing data we might have for this revision since
105105
# we never want our records to be out of sync with the actual VCS:
106-
107-
# We need to convert the timezone-aware date to a naive (i.e.
108-
# timezone-less) date in UTC to avoid killing MySQL:
109-
revision.date = date.astimezone(
110-
isodate.tzinfo.Utc()).replace(tzinfo=None)
106+
if not getattr(settings, 'USE_TZ_AWARE_DATES', False):
107+
# We need to convert the timezone-aware date to a naive (i.e.
108+
# timezone-less) date in UTC to avoid killing MySQL:
109+
logger.debug('USE_TZ_AWARE_DATES setting is set to False, '
110+
'converting datetime object to a naive one')
111+
revision.date = date.astimezone(
112+
isodate.tzinfo.Utc()).replace(tzinfo=None)
111113
revision.author = commit_json['author']['name']
112114
revision.message = commit_json['message']
113115
revision.full_clean()

codespeed/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
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
8686

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.
89+
8790
GITHUB_OAUTH_TOKEN = None # Github oAuth token to use when using Github repo type. If not
8891
# specified, it will utilize unauthenticated requests which have
8992
# low rate limits.

0 commit comments

Comments
 (0)