Skip to content

Commit 7c46537

Browse files
committed
Upgrade implementation of SQL timestamp
Signed-off-by: Patrik Dufresne <patrik@ikus-soft.com>
1 parent 4ce35fc commit 7c46537

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

rdiffweb/controller/page_pref_tokens.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
import logging
19+
from datetime import timezone
1920

2021
import cherrypy
2122
from markupsafe import Markup, escape
@@ -150,8 +151,9 @@ def is_submitted(self):
150151
return super().is_submitted() and self.add_access_token.data
151152

152153
def populate_obj(self, userobj):
154+
expiration_time = self.expiration.data.replace(tzinfo=timezone.utc) if self.expiration.data else None
153155
self.secret = userobj.add_access_token(
154-
name=self.name.data, expiration_time=self.expiration.data, scope=self.scope.data
156+
name=self.name.data, expiration_time=expiration_time, scope=self.scope.data
155157
)
156158

157159

rdiffweb/core/model/_timestamp.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,14 @@ def _render_to_tsvector_of_sqlite(element, compiler, **kw):
4343

4444

4545
class Timestamp(TypeDecorator):
46-
"""
47-
Adjust datetime to store timezone info and restore timezone
48-
info whether or not the datetime object as it.
49-
"""
50-
5146
cache_ok = True
5247
impl = DateTime
53-
LOCAL_TIMEZONE = datetime.now(timezone.utc).astimezone().tzinfo
5448

5549
def process_bind_param(self, value: datetime, dialect):
5650
if value is None:
5751
return None
5852
if value.tzinfo is None:
59-
value = value.astimezone(self.LOCAL_TIMEZONE)
53+
raise ValueError('datetime without tzinfo: %s' % value)
6054
return value.astimezone(timezone.utc)
6155

6256
def process_result_value(self, value, dialect):

0 commit comments

Comments
 (0)