2022-12-09 13:40:42 +08:00
|
|
|
diff -Naur a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
|
|
|
|
|
--- a/django/db/backends/base/operations.py 2022-12-06 17:12:38.000000000 +0800
|
|
|
|
|
+++ b/django/db/backends/base/operations.py 2022-12-09 11:49:05.347986919 +0800
|
2022-07-05 17:23:06 +08:00
|
|
|
@@ -9,6 +9,7 @@
|
|
|
|
|
from django.db.backends import utils
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from django.utils.encoding import force_str
|
|
|
|
|
+from django.utils.regex_helper import _lazy_re_compile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseDatabaseOperations:
|
2022-12-09 13:40:42 +08:00
|
|
|
@@ -53,6 +54,8 @@
|
|
|
|
|
|
2022-07-05 17:23:06 +08:00
|
|
|
# Prefix for EXPLAIN queries, or None EXPLAIN isn't supported.
|
|
|
|
|
explain_prefix = None
|
|
|
|
|
+ extract_trunc_lookup_pattern = _lazy_re_compile(r"[\w\-_()]+")
|
|
|
|
|
+
|
2022-12-09 13:40:42 +08:00
|
|
|
|
2022-07-05 17:23:06 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
|
self.connection = connection
|
2022-12-09 13:40:42 +08:00
|
|
|
diff -Naur a/django/db/models/functions/datetime.py b/django/db/models/functions/datetime.py
|
|
|
|
|
--- a/django/db/models/functions/datetime.py 2022-12-06 17:12:38.000000000 +0800
|
|
|
|
|
+++ b/django/db/models/functions/datetime.py 2022-12-09 11:50:50.011981885 +0800
|
|
|
|
|
@@ -51,6 +51,8 @@
|
2022-07-05 17:23:06 +08:00
|
|
|
super().__init__(expression, **extra)
|
|
|
|
|
|
|
|
|
|
def as_sql(self, compiler, connection):
|
|
|
|
|
+ if not connection.ops.extract_trunc_lookup_pattern.fullmatch(self.lookup_name):
|
|
|
|
|
+ raise ValueError("Invalid lookup_name: %s" % self.lookup_name)
|
|
|
|
|
sql, params = compiler.compile(self.lhs)
|
|
|
|
|
lhs_output_field = self.lhs.output_field
|
|
|
|
|
if isinstance(lhs_output_field, DateTimeField):
|
2022-12-09 13:40:42 +08:00
|
|
|
@@ -243,6 +245,8 @@
|
2022-07-05 17:23:06 +08:00
|
|
|
super().__init__(expression, output_field=output_field, **extra)
|
|
|
|
|
|
|
|
|
|
def as_sql(self, compiler, connection):
|
|
|
|
|
+ if not connection.ops.extract_trunc_lookup_pattern.fullmatch(self.kind):
|
|
|
|
|
+ raise ValueError("Invalid kind: %s" % self.kind)
|
2022-12-09 13:40:42 +08:00
|
|
|
sql, params = compiler.compile(self.lhs)
|
2022-07-05 17:23:06 +08:00
|
|
|
tzname = None
|
|
|
|
|
if isinstance(self.lhs.output_field, DateTimeField):
|