1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #28370 -- Moved db converters deprecation warning to improve performance.

This commit is contained in:
Sergey Fedoseev 2017-08-01 17:05:32 +05:00 committed by Tim Graham
parent 58da81a5a3
commit 62dee1483d

View File

@ -1,4 +1,5 @@
import collections import collections
import functools
import re import re
import warnings import warnings
from itertools import chain from itertools import chain
@ -921,7 +922,20 @@ class SQLCompiler:
backend_converters = self.connection.ops.get_db_converters(expression) backend_converters = self.connection.ops.get_db_converters(expression)
field_converters = expression.get_db_converters(self.connection) field_converters = expression.get_db_converters(self.connection)
if backend_converters or field_converters: if backend_converters or field_converters:
converters[i] = (backend_converters + field_converters, expression) convs = []
for conv in (backend_converters + field_converters):
if func_supports_parameter(conv, 'context'):
warnings.warn(
'Remove the context parameter from %s.%s(). Support for it '
'will be removed in Django 3.0.' % (
conv.__self__.__class__.__name__,
conv.__name__,
),
RemovedInDjango30Warning,
)
conv = functools.partial(conv, context={})
convs.append(conv)
converters[i] = (convs, expression)
return converters return converters
def apply_converters(self, row, converters): def apply_converters(self, row, converters):
@ -929,18 +943,7 @@ class SQLCompiler:
for pos, (convs, expression) in converters.items(): for pos, (convs, expression) in converters.items():
value = row[pos] value = row[pos]
for converter in convs: for converter in convs:
if func_supports_parameter(converter, 'context'): value = converter(value, expression, self.connection)
warnings.warn(
'Remove the context parameter from %s.%s(). Support for it '
'will be removed in Django 3.0.' % (
converter.__self__.__class__.__name__,
converter.__name__,
),
RemovedInDjango30Warning,
)
value = converter(value, expression, self.connection, {})
else:
value = converter(value, expression, self.connection)
row[pos] = value row[pos] = value
return tuple(row) return tuple(row)