apps: force DateTimeField timezone to UTC (#46038)

DRF 3.7 changed the default timezone used by the DateTimeField
serializer field for the default timezone of Django instead of UTC. To
keep GLC plugin retrocompatible we force it to UTC again.

References:
https://www.django-rest-framework.org/community/release-notes/#370
https://github.com/encode/django-rest-framework/pull/5435
This commit is contained in:
Benjamin Dauvergne 2020-08-24 17:37:12 +02:00
parent 771205afa0
commit fb55d92d3b
2 changed files with 6 additions and 1 deletions

View File

@ -22,7 +22,7 @@ import django.apps
from django.conf import settings
from django.db import router, DEFAULT_DB_ALIAS
from django.utils.timezone import now
from django.utils.timezone import now, utc
from django.urls import reverse_lazy
@ -364,6 +364,9 @@ class AppConfig(django.apps.AppConfig):
return data
serializer.validate = new_validate
serializer.fields['modified'].timezone = utc
serializer.fields['date_joined'].timezone = utc
# execute after other modifiers
a2_hook_api_modify_serializer.order = 999

View File

@ -30,6 +30,8 @@ def john(glc_app):
assert response.json['first_name'] == JOHN
assert response.json['last_name'] == DOE
assert response.json['email'] == EMAIL
assert response.json['date_joined'].endswith('Z')
assert response.json['modified'].endswith('Z')
assert user.first_name == JOHN
assert user.last_name == DOE
assert user.email == EMAIL