[CalendarServer-changes] [6915] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Feb 8 16:07:47 PST 2011
Revision: 6915
http://trac.macosforge.org/projects/calendarserver/changeset/6915
Author: cdaboo at apple.com
Date: 2011-02-08 16:07:45 -0800 (Tue, 08 Feb 2011)
Log Message:
-----------
Fix bug causing a 500 error when an SQL timestamp does not have fraction seconds.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/dateops.py
CalendarServer/trunk/txdav/caldav/datastore/sql.py
CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
CalendarServer/trunk/txdav/common/datastore/sql.py
Modified: CalendarServer/trunk/twistedcaldav/dateops.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/dateops.py 2011-02-08 23:16:17 UTC (rev 6914)
+++ CalendarServer/trunk/twistedcaldav/dateops.py 2011-02-09 00:07:45 UTC (rev 6915)
@@ -223,7 +223,14 @@
return (start, end - start)
else:
return (start, end)
-
+
+def parseSQLTimestamp(ts):
+
+ # Handle case where fraction seconds may not be present
+ if len(ts) < 20:
+ ts += ".0"
+ return datetime.datetime.strptime(ts, "%Y-%m-%d %H:%M:%S.%f")
+
def datetimeMktime(dt):
assert isinstance(dt, datetime.date)
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2011-02-08 23:16:17 UTC (rev 6914)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2011-02-09 00:07:45 UTC (rev 6915)
@@ -37,7 +37,8 @@
from twistedcaldav import caldavxml, customxml
from twistedcaldav.caldavxml import ScheduleCalendarTransp, Opaque
-from twistedcaldav.dateops import normalizeForIndex, datetimeMktime
+from twistedcaldav.dateops import normalizeForIndex, datetimeMktime,\
+ parseSQLTimestamp
from twistedcaldav.ical import Component
from twistedcaldav.instance import InvalidOverriddenInstanceError
from twistedcaldav.memcacher import Memcacher
@@ -780,7 +781,7 @@
def sqltime(value):
- return datetimeMktime(datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f"))
+ return datetimeMktime(parseSQLTimestamp(value))
class Attachment(object):
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2011-02-08 23:16:17 UTC (rev 6914)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2011-02-09 00:07:45 UTC (rev 6915)
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
+import datetime
+from twistedcaldav.dateops import datetimeMktime
"""
Tests for txdav.caldav.datastore.postgres, mostly based on
@@ -370,3 +372,23 @@
yield d1
yield d2
+
+ @inlineCallbacks
+ def test_datetimes(self):
+ calendarStore = self._sqlCalendarStore
+
+ # Provision the home and calendar now
+ txn = calendarStore.newTransaction()
+ home = yield txn.homeWithUID(ECALENDARTYPE, "uid1", create=True)
+ cal = yield home.calendarWithName("calendar")
+ cal._created = "2011-02-05 11:22:47"
+ cal._modified = "2011-02-06 11:22:47"
+ self.assertEqual(cal.created(), datetimeMktime(datetime.datetime(2011, 2, 5, 11, 22, 47)))
+ self.assertEqual(cal.modified(), datetimeMktime(datetime.datetime(2011, 2, 6, 11, 22, 47)))
+
+ obj = yield self.calendarObjectUnderTest()
+ obj._created = "2011-02-07 11:22:47"
+ obj._modified = "2011-02-08 11:22:47"
+ self.assertEqual(obj.created(), datetimeMktime(datetime.datetime(2011, 2, 7, 11, 22, 47)))
+ self.assertEqual(obj.modified(), datetimeMktime(datetime.datetime(2011, 2, 8, 11, 22, 47)))
+
\ No newline at end of file
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2011-02-08 23:16:17 UTC (rev 6914)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2011-02-09 00:07:45 UTC (rev 6915)
@@ -68,7 +68,7 @@
from txdav.base.propertystore.sql import PropertyStore
from twistedcaldav.customxml import NotificationType
-from twistedcaldav.dateops import datetimeMktime
+from twistedcaldav.dateops import datetimeMktime, parseSQLTimestamp
v1_schema = getModule(__name__).filePath.sibling("sql_schema_v1.sql").getContent()
@@ -1682,11 +1682,11 @@
def created(self):
- return datetimeMktime(datetime.datetime.strptime(self._created, "%Y-%m-%d %H:%M:%S.%f")) if self._created else None
+ return datetimeMktime(parseSQLTimestamp(self._created)) if self._created else None
def modified(self):
- return datetimeMktime(datetime.datetime.strptime(self._modified, "%Y-%m-%d %H:%M:%S.%f")) if self._modified else None
+ return datetimeMktime(parseSQLTimestamp(self._modified)) if self._modified else None
def addNotifier(self, notifier):
@@ -1959,13 +1959,11 @@
def created(self):
- utc = datetime.datetime.strptime(self._created, "%Y-%m-%d %H:%M:%S.%f")
- return datetimeMktime(utc)
+ return datetimeMktime(parseSQLTimestamp(self._created))
def modified(self):
- utc = datetime.datetime.strptime(self._modified, "%Y-%m-%d %H:%M:%S.%f")
- return datetimeMktime(utc)
+ return datetimeMktime(parseSQLTimestamp(self._modified))
@inlineCallbacks
@@ -2519,13 +2517,11 @@
return self._xmlType
def created(self):
- utc = datetime.datetime.strptime(self._created, "%Y-%m-%d %H:%M:%S.%f")
- return datetimeMktime(utc)
+ return datetimeMktime(parseSQLTimestamp(self._created))
def modified(self):
- utc = datetime.datetime.strptime(self._modified, "%Y-%m-%d %H:%M:%S.%f")
- return datetimeMktime(utc)
+ return datetimeMktime(parseSQLTimestamp(self._modified))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110208/bbd868a5/attachment.html>
More information about the calendarserver-changes
mailing list