← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:fix-oopsreference-tests into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:fix-oopsreference-tests into launchpad:master.

Commit message:
Restore special datetime handling to sqlbase.quote

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/451890

I dropped this while dropping `SQLBase` thinking it was no longer needed, but it seems as though `sqlrepr` drops the microsecond part from datetimes which breaks some tests, so we still need to deal with that.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-oopsreference-tests into launchpad:master.
diff --git a/lib/lp/services/database/sqlbase.py b/lib/lp/services/database/sqlbase.py
index d24dd95..f604f4c 100644
--- a/lib/lp/services/database/sqlbase.py
+++ b/lib/lp/services/database/sqlbase.py
@@ -23,7 +23,7 @@ __all__ = [
     "StupidCache",
 ]
 
-from datetime import timezone
+from datetime import datetime, timezone
 
 import psycopg2
 import transaction
@@ -149,7 +149,9 @@ def quote(x):
 
     >>> from datetime import datetime, date, time
     >>> quote(datetime(2003, 12, 4, 13, 45, 50))
-    "'2003-12-04T13:45:50'"
+    "'2003-12-04 13:45:50'"
+    >>> quote(datetime(2003, 12, 4, 13, 45, 50, 123456))
+    "'2003-12-04 13:45:50.123456'"
     >>> quote(date(2003, 12, 4))
     "'2003-12-04'"
     >>> quote(time(13, 45, 50))
@@ -163,6 +165,8 @@ def quote(x):
     >>> quote(frozenset([1, 2, 3]))
     '(1, 2, 3)'
     """
+    if isinstance(x, datetime):
+        return "'%s'" % x
     return sqlrepr(x, "postgres")