Repository: googleapis/python-spanner-django

Issue:
DateTimeField returns DatetimeWithNanoseconds instead of datetime
Following https://github.com/orijtech/spanner-orm/pull/83:
```
======================================================================
FAIL: test_for_datetimefields_saves_as_much_precision_as_was_given (basic.tests.ModelInstanceCreationTests)
as much precision in *seconds*
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/tests/basic/tests.py", line 98, in test_for_datetimefields_saves_as_much_precision_as_was_given
    self.assertEqual(Article.objects.get(id__exact=a1.id).pub_date, datetime(2005, 7, 31, 12, 30))
AssertionError: DatetimeWithNanoseconds(2005, 7, 31, 12, 30, tzinfo=<UTC>) != datetime.datetime(2005, 7, 31, 12, 30)
```
`DatabaseOperations.convert_datetimefield_value()` (as I commented on the PR) isn't correct.


Discussion:
For fuller context
```shell
ERROR: test_refresh (basic.tests.ModelRefreshTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emmanuelodeke/Desktop/spanner-orm/django_tests/django/tests/basic/tests.py", line 638, in test_refresh
    Article.objects.update(headline='new headline 2', pub_date=new_pub_date)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/query.py", line 741, in update
    rows = query.get_compiler(self.db).execute_sql(CURSOR)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/sql/compiler.py", line 1429, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/sql/compiler.py", line 1087, in execute_sql
    sql, params = self.as_sql()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/sql/compiler.py", line 1395, in as_sql
    val = field.get_db_prep_save(val, connection=self.connection)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/fields/__init__.py", line 793, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Django-2.2.8.dev20191126193909-py3.7.egg/django/db/models/fields/__init__.py", line 1436, in get_db_prep_value
    return connection.ops.adapt_datetimefield_value(value)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spanner/django/operations.py", line 43, in adapt_datetimefield_value
    raise ValueError("Cloud Spanner does not support timezone-aware datetimes when USE_TZ is False.")
ValueError: Cloud Spanner does not support timezone-aware datetimes when USE_TZ is False.
```

Resolving patch:
diff --git a/spanner/django/operations.py b/spanner/django/operations.py
--- a/spanner/django/operations.py
+++ b/spanner/django/operations.py
@@ -1,3 +1,5 @@
+from datetime import datetime
+
 from django.conf import settings
 from django.db.backends.base.operations import BaseDatabaseOperations
 from django.utils import timezone
@@ -53,6 +55,13 @@ def get_db_converters(self, expression):
     def convert_datetimefield_value(self, value, expression, connection):
         if value is None:
             return value
-        if timezone.is_aware(value):
-            return value
-        return timezone.make_aware(value, self.connection.timezone)
+        # Cloud Spanner returns the
+        # google.api_core.datetime_helpers.DatetimeWithNanoseconds subclass
+        # of datetime with tzinfo=UTC (which should be replaced with the
+        # connection's timezone). Django doesn't support nanoseconds so that
+        # part is ignored.
+        return datetime(
+            value.year, value.month, value.day,
+            value.hour, value.minute, value.second, value.microsecond,
+            self.connection.timezone,
+        )


Test patch: