Repository: zulip/zulip

Issue:
Naive datetime warnings in populate_db
This output is generated every time we provision:

```
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.072319) while time zone support is active.
  RuntimeWarning)
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.082099) while time zone support is active.
  RuntimeWarning)
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.085108) while time zone support is active.
  RuntimeWarning)
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.088053) while time zone support is active.
  RuntimeWarning)
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.090953) while time zone support is active.
  RuntimeWarning)
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.094410) while time zone support is active.
  RuntimeWarning)
/srv/zulip-venv-cache/2ded3ad4731e6a2943352f72cd4f555ecd484fc5/zulip-py3-venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py:1430: RuntimeWarning: DateTimeField UserPresence.timestamp received a naive datetime (2016-12-15 19:38:41.097529) while time zone support is active.
```

I think this is a regression introduced in #2626, but masked by the fact that these warnings may not have been displayed before the Django 1.10 upgrade.

The solution is to use timezone-aware datetime objects; we do this generally with `django.util.timezone.now()` in Zulip.


Discussion:
Looking on this..

Resolving patch:
diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py
--- a/zilencer/management/commands/populate_db.py
+++ b/zilencer/management/commands/populate_db.py
@@ -17,7 +17,6 @@
     bulk_create_clients
 from zerver.models import DefaultStream, get_stream, get_realm_by_string_id
 from zilencer.models import Deployment
-import datetime
 
 import random
 import os
@@ -183,7 +182,7 @@ def handle(self, **options):
             # Populate users with some bar data
             for user in user_profiles:
                 status = 1 # type: int
-                date = datetime.datetime.now() # type: datetime.datetime
+                date = now()
                 client = get_client("website")
                 for i in range(3):
                     client = get_client("API")


Test patch: