From nobody Fri Mar 29 00:30:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=patchew-devel-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605880008; cv=none; d=zohomail.com; s=zohoarc; b=b0k9hh06UVFmH15Lwyc9Dnl2IfIgT70jkGiHzs9hm8Oc+aSHSGBz0ONVe4p4LBtKG63iYWXvt9e9pvDypIXul6UrwZsNoNzVdXYPAGpPA/XT7CKkOJBOQD9rq/e+MwPbWQ74XEqSYD0kCLUpyz7PMBvrBtzj8dkNsw7uTRTBSXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605880008; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=MSJF/JNELRZsoi2K3rBqvmFn9h3XCE2tw+MTMvZvbgQ=; b=FGh0pxY7GZ+ACr2x54lyjzwqOZrfgd5vdjVy36elJw7B1aJEn0ryoYwrkUQP7RnBKfec8c2y4pnP1GIM+dv/TbJNhzvqY9jR/azh3WFH01DktINGn9KF8ZGgx8tk3ElwIxU9FZqyqjytAdsuqzYapWbF3BUSvTY9TSpVqT2QwBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605880008354198.105547431481; Fri, 20 Nov 2020 05:46:48 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-Da9dxIvzP1yZ5oDrHpK27w-1; Fri, 20 Nov 2020 08:46:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9725F106B250; Fri, 20 Nov 2020 13:46:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EB0919D7D; Fri, 20 Nov 2020 13:46:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5E2311809C9F; Fri, 20 Nov 2020 13:46:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AKDkfKh030132 for ; Fri, 20 Nov 2020 08:46:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 757E060C17; Fri, 20 Nov 2020 13:46:41 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-204.ams2.redhat.com [10.36.112.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB10160C15 for ; Fri, 20 Nov 2020 13:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605880007; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=MSJF/JNELRZsoi2K3rBqvmFn9h3XCE2tw+MTMvZvbgQ=; b=aksIgBr1FGVnCW6L2X3DTzHEH+T3YgCiFHVqSUpeYWqznTNsDk4StjcM/js0nCHYrTF5zy JUZ1W0jTzbVlmE8BmnjxDhQPhi+7B6ZLT7EI6/ulv8HFk3lCpbEY9BHtZKtEskWeGQbppt EdXQyvXCQA7Y24cXnNIaMZ3B6fsR4rw= X-MC-Unique: Da9dxIvzP1yZ5oDrHpK27w-1 From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 20 Nov 2020 14:46:34 +0100 Message-Id: <20201120134634.152020-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] fix NonNullSearchVector for new django X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=patchew-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" More recent Django has moved the COALESCEing of SearchVector arguments from __init__ to as_sql. Adjust NonNullSearchVector to monkeypatch as_sql instead of __init__. Signed-off-by: Paolo Bonzini --- api/search.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/api/search.py b/api/search.py index 4f6650c..5d4529d 100644 --- a/api/search.py +++ b/api/search.py @@ -35,18 +35,32 @@ class InvalidSearchTerm(Exception): =20 =20 # Hack alert: Django wraps each argument to to_tsvector with a COALESCE fu= nction, -# and that causes postgres not to use the index. Monkeypatch the construc= tor -# to skip that step, which we do not need since the subject field is not n= ullable. +# and that causes postgres not to use the index. Monkeypatch as_sql to sk= ip +# that step, which we do not need since the subject field is not nullable. class NonNullSearchVector(SearchVector): function =3D "to_tsvector" arg_joiner =3D " || ' ' || " _output_field =3D SearchVectorField() - config =3D None =20 - def __init__(self, *expressions, **extra): - super(SearchVector, self).__init__(*expressions, **extra) - self.config =3D self.extra.get("config", self.config) - self.weight =3D None + def as_sql(self, compiler, connection, function=3DNone, template=3DNon= e): + config_sql =3D None + config_params =3D [] + if template is None: + if self.config: + config_sql, config_params =3D compiler.compile(self.config) + template =3D '%(function)s(%(config)s, %(expressions)s)' + else: + template =3D self.template + sql, params =3D super(SearchVector, self).as_sql( + compiler, connection, function=3Dfunction, template=3Dtemplate, + config=3Dconfig_sql, + ) + extra_params =3D [] + if self.weight: + weight_sql, extra_params =3D compiler.compile(self.weight) + sql =3D 'setweight({}, {})'.format(sql, weight_sql) + return sql, config_params + params + extra_params + =20 =20 class SearchEngine(object): --=20 2.28.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel