mirror of
https://github.com/simonw/datasette.git
synced 2026-11-25 11:29:43 +01:00
parent
cf113a5985
commit
e1a4e03635
16 changed files with 24 additions and 47 deletions
|
|
@ -2212,7 +2212,7 @@ ORDER BY allowed.parent, allowed.child
|
|||
|
||||
# Log every check (including cache hits) for the debug page,
|
||||
# dependencies before the actions that required them
|
||||
when = datetime.datetime.now(datetime.timezone.utc).isoformat()
|
||||
when = datetime.datetime.now(datetime.UTC).isoformat()
|
||||
for name in reversed(expanded):
|
||||
self._permission_checks.append(
|
||||
PermissionCheck(
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ logger = logging.getLogger("datasette.background_tasks")
|
|||
|
||||
|
||||
def _utcnow_iso() -> str:
|
||||
return datetime.datetime.now(datetime.timezone.utc).isoformat()
|
||||
return datetime.datetime.now(datetime.UTC).isoformat()
|
||||
|
||||
|
||||
def _function_path(func: Callable) -> str:
|
||||
|
|
|
|||
|
|
@ -25,12 +25,9 @@ def now(key, request):
|
|||
if key == "epoch":
|
||||
return int(time.time())
|
||||
elif key == "date_utc":
|
||||
return datetime.datetime.now(datetime.timezone.utc).date().isoformat()
|
||||
return datetime.datetime.now(datetime.UTC).date().isoformat()
|
||||
elif key == "datetime_utc":
|
||||
return (
|
||||
datetime.datetime.now(datetime.timezone.utc).strftime(r"%Y-%m-%dT%H:%M:%S")
|
||||
+ "Z"
|
||||
)
|
||||
return datetime.datetime.now(datetime.UTC).strftime(r"%Y-%m-%dT%H:%M:%S") + "Z"
|
||||
else:
|
||||
raise KeyError
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from abc import ABC, abstractproperty
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from datasette.hookspecs import hookimpl
|
||||
|
||||
|
|
@ -11,9 +11,7 @@ class Event(ABC):
|
|||
def name(self):
|
||||
pass
|
||||
|
||||
created: datetime = field(
|
||||
init=False, default_factory=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
created: datetime = field(init=False, default_factory=lambda: datetime.now(UTC))
|
||||
actor: dict | None
|
||||
|
||||
def properties(self):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
|
|
@ -193,20 +192,6 @@ _AUTHORIZER_ACTION_NAMES = {
|
|||
}
|
||||
|
||||
|
||||
def _allow_authorizer_action(*args):
|
||||
return sqlite3.SQLITE_OK
|
||||
|
||||
|
||||
def _disable_authorizer(conn):
|
||||
# Python 3.11 added support for unregistering an authorizer using None.
|
||||
# On Python 3.10, None is installed as the callback instead, and the next
|
||||
# statement fails with "not authorized" when sqlite3 tries to call it.
|
||||
if sys.version_info >= (3, 11):
|
||||
conn.set_authorizer(None)
|
||||
else:
|
||||
conn.set_authorizer(_allow_authorizer_action)
|
||||
|
||||
|
||||
def analyze_sql_tables(
|
||||
conn,
|
||||
sql: str,
|
||||
|
|
@ -451,9 +436,7 @@ def analyze_sql_tables(
|
|||
explain_rows = conn.execute(
|
||||
"EXPLAIN " + sql, params if params is not None else {}
|
||||
).fetchall()
|
||||
# Passing None before these lookups leaves a failing callback installed
|
||||
# on Python 3.10, so use a permissive callback until they are complete.
|
||||
conn.set_authorizer(_allow_authorizer_action)
|
||||
conn.set_authorizer(None)
|
||||
|
||||
if not operations:
|
||||
vacuum_row = next((row for row in explain_rows if row[1] == "Vacuum"), None)
|
||||
|
|
@ -495,7 +478,7 @@ def analyze_sql_tables(
|
|||
conn, key.table, schema=key.sqlite_schema
|
||||
)
|
||||
finally:
|
||||
_disable_authorizer(conn)
|
||||
conn.set_authorizer(None)
|
||||
|
||||
has_schema_operation = any(
|
||||
key.target_type in {"table", "index", "view", "trigger", "virtual-table"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue