From nobody Fri Apr 26 23:52:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525877380527387.7669085549685; Wed, 9 May 2018 07:49:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BD3E30F087D; Wed, 9 May 2018 14:49:39 +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 7F21D30012AD; Wed, 9 May 2018 14:49:39 +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 73E4E180BADB; Wed, 9 May 2018 14:49:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w49EncZh003676 for ; Wed, 9 May 2018 10:49:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id C836510B2B47; Wed, 9 May 2018 14:49:38 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-138.ams2.redhat.com [10.36.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4080F10B2B46 for ; Wed, 9 May 2018 14:49:36 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 9 May 2018 16:49:35 +0200 Message-Id: <20180509144935.23542-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] rest: fix TypeError in the schema generator 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 09 May 2018 14:49:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The API generator calls into the serializer to get the list of fields for P= OST requests, but it does not fill in the request. This causes a TypeError when accessing the Serializer context. Signed-off-by: Paolo Bonzini --- api/rest.py | 7 ++++++- tests/test_rest.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/api/rest.py b/api/rest.py index 61c0103..9e280d4 100644 --- a/api/rest.py +++ b/api/rest.py @@ -300,7 +300,12 @@ class MessageSerializer(BaseMessageSerializer): =20 def get_fields(self): fields =3D super(MessageSerializer, self).get_fields() - request =3D self.context['request'] + try: + # When called from the CoreAPI schema generator, there is no c= ontext defined? + request =3D self.context['request'] + except TypeError: + request =3D None + dispatch_module_hook("rest_message_fields_hook", request=3Drequest, fields=3Dfields) return fields diff --git a/tests/test_rest.py b/tests/test_rest.py index 6d86053..6a9c332 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -10,6 +10,8 @@ =20 import sys import os +import json +import unittest =20 from django.contrib.auth.models import User =20 @@ -18,7 +20,11 @@ from patchewtest import PatchewTestCase, main from api.models import Message from api.rest import AddressSerializer from collections import OrderedDict -import json + +try: + import coreapi +except ImportError: + coreapi =3D None =20 class RestTest(PatchewTestCase): def setUp(self): @@ -325,5 +331,9 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data['results'][3]['resource_uri'], self.PRO= JECT_BASE + 'messages/e0858c00-ccb6-e533-ee3e-9ba84ca45a7b@redhat.com/') self.assertEqual(resp.data['results'][3]['subject'], 'Re: [Qemu-de= vel] [PATCH v4 0/2] Report format specific info for LUKS block driver') =20 + def test_schema(self): + resp =3D self.api_client.get(self.REST_BASE + 'schema/') + self.assertEqual(resp.status_code, 200) + if __name__ =3D=3D '__main__': main() --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel