From fa4b2c15f27edf8d6b8c88b451e23824ddec928c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 23 Dec 2021 06:54:06 +0100 Subject: [PATCH] Refs #33355 -- Optimized LPad() database function on SQLite. Co-Authored-By: Nick Pope --- django/db/backends/sqlite3/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 39e3e43e47..7ec6466b1b 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -615,9 +615,10 @@ def _sqlite_regexp(re_pattern, re_string): @none_guard def _sqlite_lpad(text, length, fill_text): - if len(text) >= length: + delta = length - len(text) + if delta <= 0: return text[:length] - return (fill_text * length)[:length - len(text)] + text + return (fill_text * length)[:delta] + text @none_guard