[snowy: 7/8] Strip time zone info before saving to datetimes to database



commit af3cafa9fe1614a1e0fcab23bbe62627e2c0ffcf
Author: Leon Handreke <leon handreke gmail com>
Date:   Fri Feb 19 20:20:05 2010 +0100

    Strip time zone info before saving to datetimes to database
    
    This fixes an issue with using mysql as a database backend

 api/handlers.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/api/handlers.py b/api/handlers.py
index 68da988..5a6d229 100644
--- a/api/handlers.py
+++ b/api/handlers.py
@@ -128,7 +128,10 @@ class NotesHandler(BaseHandler):
     @transaction.commit_on_success
     def update(self, request, username):
         def clean_date(date):
-            return parser.parse(date).astimezone(pytz.utc)
+            """Set tzinfo=None because some DB engines do not accept
+            timezone-aware dates. As long as all dates in the database
+            are UTC, this is not a problem."""
+            return parser.parse(date).astimezone(pytz.utc).replace(tzinfo=None)
 
         author = User.objects.get(username=username)
         if request.user != author:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]