← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:abolish-utcdatetimecol into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:abolish-utcdatetimecol into launchpad:master.

Commit message:
Remove remaining uses of UtcDateTimeCol

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/451832
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:abolish-utcdatetimecol into launchpad:master.
diff --git a/lib/lp/blueprints/model/specificationworkitem.py b/lib/lp/blueprints/model/specificationworkitem.py
index 79f9316..23ac31b 100644
--- a/lib/lp/blueprints/model/specificationworkitem.py
+++ b/lib/lp/blueprints/model/specificationworkitem.py
@@ -5,7 +5,9 @@ __all__ = [
     "SpecificationWorkItem",
 ]
 
-from storm.locals import Bool, Int, Reference, Unicode
+from datetime import timezone
+
+from storm.locals import Bool, DateTime, Int, Reference, Unicode
 from storm.store import Store
 from zope.interface import implementer
 
@@ -16,7 +18,6 @@ from lp.blueprints.interfaces.specificationworkitem import (
 )
 from lp.registry.interfaces.person import validate_public_person
 from lp.services.database.constants import DEFAULT
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.enumcol import DBEnum
 from lp.services.database.stormbase import StormBase
 from lp.services.helpers import backslashreplace
@@ -40,7 +41,9 @@ class SpecificationWorkItem(StormBase):
         allow_none=False,
         default=SpecificationWorkItemStatus.TODO,
     )
-    date_created = UtcDateTimeCol(notNull=True, default=DEFAULT)
+    date_created = DateTime(
+        allow_none=False, default=DEFAULT, tzinfo=timezone.utc
+    )
     sequence = Int(allow_none=False)
     deleted = Bool(allow_none=False, default=False)
 
diff --git a/lib/lp/blueprints/model/sprintattendance.py b/lib/lp/blueprints/model/sprintattendance.py
index 693d4f3..82b677b 100644
--- a/lib/lp/blueprints/model/sprintattendance.py
+++ b/lib/lp/blueprints/model/sprintattendance.py
@@ -3,12 +3,13 @@
 
 __all__ = ["SprintAttendance"]
 
-from storm.locals import Bool, Int, Reference
+from datetime import timezone
+
+from storm.locals import Bool, DateTime, Int, Reference
 from zope.interface import implementer
 
 from lp.blueprints.interfaces.sprintattendance import ISprintAttendance
 from lp.registry.interfaces.person import validate_public_person
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.stormbase import StormBase
 
 
@@ -26,8 +27,8 @@ class SprintAttendance(StormBase):
     attendeeID = Int(name="attendee", validator=validate_public_person)
     attendee = Reference(attendeeID, "Person.id")
 
-    time_starts = UtcDateTimeCol(notNull=True)
-    time_ends = UtcDateTimeCol(notNull=True)
+    time_starts = DateTime(allow_none=False, tzinfo=timezone.utc)
+    time_ends = DateTime(allow_none=False, tzinfo=timezone.utc)
     _is_physical = Bool(name="is_physical", default=True)
 
     def __init__(self, sprint, attendee):
diff --git a/lib/lp/code/model/sourcepackagerecipe.py b/lib/lp/code/model/sourcepackagerecipe.py
index 937024a..4cd3891 100644
--- a/lib/lp/code/model/sourcepackagerecipe.py
+++ b/lib/lp/code/model/sourcepackagerecipe.py
@@ -15,6 +15,7 @@ from lazr.delegates import delegate_to
 from storm.expr import And, LeftJoin
 from storm.locals import (
     Bool,
+    DateTime,
     Desc,
     Int,
     Reference,
@@ -44,7 +45,6 @@ from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.registry.model.distroseries import DistroSeries
 from lp.services.database.bulk import load_referencing
 from lp.services.database.constants import DEFAULT, UTC_NOW
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.interfaces import IPrimaryStore, IStore
 from lp.services.database.stormbase import StormBase
 from lp.services.database.stormexpr import Greatest, NullsLast
@@ -95,8 +95,8 @@ class SourcePackageRecipe(StormBase):
     daily_build_archive_id = Int(name="daily_build_archive", allow_none=True)
     daily_build_archive = Reference(daily_build_archive_id, "Archive.id")
 
-    date_created = UtcDateTimeCol(notNull=True)
-    date_last_modified = UtcDateTimeCol(notNull=True)
+    date_created = DateTime(allow_none=False, tzinfo=timezone.utc)
+    date_last_modified = DateTime(allow_none=False, tzinfo=timezone.utc)
 
     owner_id = Int(name="owner", allow_none=True)
     owner = Reference(owner_id, "Person.id")
diff --git a/lib/lp/services/apachelogparser/model/parsedapachelog.py b/lib/lp/services/apachelogparser/model/parsedapachelog.py
index 66a4b35..f8541da 100644
--- a/lib/lp/services/apachelogparser/model/parsedapachelog.py
+++ b/lib/lp/services/apachelogparser/model/parsedapachelog.py
@@ -3,15 +3,16 @@
 
 __all__ = ["ParsedApacheLog"]
 
+from datetime import timezone
+
 import six
-from storm.locals import Int, Unicode
+from storm.locals import DateTime, Int, Unicode
 from zope.interface import implementer
 
 from lp.services.apachelogparser.interfaces.parsedapachelog import (
     IParsedApacheLog,
 )
 from lp.services.database.constants import UTC_NOW
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.interfaces import IStore
 from lp.services.database.stormbase import StormBase
 
@@ -25,7 +26,9 @@ class ParsedApacheLog(StormBase):
     id = Int(primary=True)
     first_line = Unicode(allow_none=False)
     bytes_read = Int(allow_none=False)
-    date_last_parsed = UtcDateTimeCol(notNull=True, default=UTC_NOW)
+    date_last_parsed = DateTime(
+        allow_none=False, default=UTC_NOW, tzinfo=timezone.utc
+    )
 
     def __init__(self, first_line, bytes_read):
         super().__init__()
diff --git a/lib/lp/services/database/datetimecol.py b/lib/lp/services/database/datetimecol.py
deleted file mode 100644
index b23a381..0000000
--- a/lib/lp/services/database/datetimecol.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""UtcDateTimeCol for SQLObject"""
-
-__all__ = ["UtcDateTimeCol"]
-
-from datetime import timezone
-
-import storm.sqlobject
-
-
-class UtcDateTimeCol(storm.sqlobject.UtcDateTimeCol):
-    _kwargs = {"tzinfo": timezone.utc}
diff --git a/lib/lp/services/database/sqlobject/__init__.py b/lib/lp/services/database/sqlobject/__init__.py
index 13fabdc..e5fb5a4 100644
--- a/lib/lp/services/database/sqlobject/__init__.py
+++ b/lib/lp/services/database/sqlobject/__init__.py
@@ -29,7 +29,6 @@ from storm.sqlobject import (  # noqa: F401
     SQLObjectResultSet,
     SQLRelatedJoin,
     StringCol,
-    UtcDateTimeCol,
 )
 
 _sqlStringReplace = [
diff --git a/lib/lp/services/features/model.py b/lib/lp/services/features/model.py
index 29631b0..1d64a9a 100644
--- a/lib/lp/services/features/model.py
+++ b/lib/lp/services/features/model.py
@@ -13,7 +13,6 @@ import six
 from storm.locals import DateTime, Int, Reference, Unicode
 from zope.interface import implementer
 
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.interfaces import IStore
 from lp.services.database.stormbase import StormBase
 from lp.services.features.interfaces import IFeatureRules
@@ -54,7 +53,7 @@ class FeatureFlagChangelogEntry(StormBase):
     __storm_table__ = "FeatureFlagChangelogEntry"
 
     id = Int(primary=True)
-    date_changed = UtcDateTimeCol(notNull=True)
+    date_changed = DateTime(allow_none=False, tzinfo=timezone.utc)
     diff = Unicode(allow_none=False)
     comment = Unicode(allow_none=False)
     person_id = Int(name="person", allow_none=False)
diff --git a/lib/lp/services/openid/model/openididentifier.py b/lib/lp/services/openid/model/openididentifier.py
index 18ef165..923c7e5 100644
--- a/lib/lp/services/openid/model/openididentifier.py
+++ b/lib/lp/services/openid/model/openididentifier.py
@@ -5,10 +5,11 @@
 
 __all__ = ["OpenIdIdentifier"]
 
-from storm.locals import Int, Reference, Unicode
+from datetime import timezone
+
+from storm.locals import DateTime, Int, Reference, Unicode
 
 from lp.services.database.constants import UTC_NOW
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.stormbase import StormBase
 
 
@@ -19,4 +20,6 @@ class OpenIdIdentifier(StormBase):
     identifier = Unicode(primary=True)
     account_id = Int("account")
     account = Reference(account_id, "Account.id")
-    date_created = UtcDateTimeCol(notNull=True, default=UTC_NOW)
+    date_created = DateTime(
+        allow_none=False, default=UTC_NOW, tzinfo=timezone.utc
+    )
diff --git a/lib/lp/services/session/model.py b/lib/lp/services/session/model.py
index b54d290..8ab900c 100644
--- a/lib/lp/services/session/model.py
+++ b/lib/lp/services/session/model.py
@@ -5,10 +5,11 @@
 
 __all__ = ["SessionData", "SessionPkgData"]
 
-from storm.locals import Pickle, Unicode
+from datetime import timezone
+
+from storm.locals import DateTime, Pickle, Unicode
 from zope.interface import implementer, provider
 
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.stormbase import StormBase
 from lp.services.session.interfaces import IUseSessionStore
 
@@ -20,8 +21,8 @@ class SessionData(StormBase):
 
     __storm_table__ = "SessionData"
     client_id = Unicode(primary=True)
-    created = UtcDateTimeCol()
-    last_accessed = UtcDateTimeCol()
+    created = DateTime(tzinfo=timezone.utc)
+    last_accessed = DateTime(tzinfo=timezone.utc)
 
 
 @implementer(IUseSessionStore)