Skip to content

Commit

Permalink
NXDRIVE-2967: Upgrade the deprecated datetime adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofanindya committed Oct 7, 2024
1 parent 462f0a0 commit aa11d4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 18 additions & 1 deletion nxdrive/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,24 @@ def execute(self, sql: str, parameters: Iterable[Any] = ()) -> Cursor:
while True:
count += 1
try:
return super().execute(sql, parameters)
if parameters:
import datetime
import sqlite3
new_param = []
for param in parameters:
if type(param) == datetime.datetime:
def adapt_datetime_iso(val):
return datetime.datetime.fromtimestamp(str(val), datetime.UTC)
mtime = sqlite3.register_adapter(param, adapt_datetime_iso)
new_param.append(mtime)
else:
new_param.append(param)

new_param = tuple(new_param)
res = super().execute(sql, new_param)
else:
res = super().execute(sql, parameters)
return res
except OperationalError as exc:
log.info(
f"Retry locked database #{count}, {sql=}, {parameters=}",
Expand Down
4 changes: 0 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ def no_warnings(recwarn):
continue
elif "Cryptography will be significantly faster" in message:
continue
elif "The default datetime adapter is deprecated as of Python 3.12" in message:
continue
elif "datetime.datetime" in message:
continue

warn = f"{warning.filename}:{warning.lineno} {message}"
print(warn, file=sys.stderr)
Expand Down

0 comments on commit aa11d4e

Please sign in to comment.