From 62dee1483da44f7593544ea20149326e5926ab9b Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Tue, 1 Aug 2017 17:05:32 +0500 Subject: [PATCH] Refs #28370 -- Moved db converters deprecation warning to improve performance. --- django/db/models/sql/compiler.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 980f6ee79f0..2abfd2c289c 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1,4 +1,5 @@ import collections +import functools import re import warnings from itertools import chain @@ -921,7 +922,20 @@ class SQLCompiler: backend_converters = self.connection.ops.get_db_converters(expression) field_converters = expression.get_db_converters(self.connection) 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 def apply_converters(self, row, converters): @@ -929,18 +943,7 @@ class SQLCompiler: for pos, (convs, expression) in converters.items(): value = row[pos] for converter in convs: - if func_supports_parameter(converter, 'context'): - 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) + value = converter(value, expression, self.connection) row[pos] = value return tuple(row)