[PATCH] [py3] ensure AjaxController return bytes

Philippe Pepiot philippe.pepiot at logilab.fr
Fri Jun 15 17:48:26 CEST 2018

# HG changeset patch
# User Philippe Pepiot <philippe.pepiot at logilab.fr>
# Date 1529077526 -7200
#      Fri Jun 15 17:45:26 2018 +0200
# Node ID e947954e0ffc53f18df2d48b9ae36394b9502ae4
# Parent  5166a1a7e4f400d2a25a5d7531a49b2340d2ebc2
# Available At https://hg.logilab.org/review/cubicweb
#              hg pull https://hg.logilab.org/review/cubicweb -r e947954e0ffc
[py3] ensure AjaxController return bytes

publish() must return bytes, when the @ajaxfunc decorated method return None, this raised:

TypeError: You cannot set Response.body to a text object (use Response.text)

diff --git a/cubicweb/web/views/ajaxcontroller.py b/cubicweb/web/views/ajaxcontroller.py
--- a/cubicweb/web/views/ajaxcontroller.py
+++ b/cubicweb/web/views/ajaxcontroller.py
@@ -163,7 +163,7 @@ class AjaxController(Controller):
                     fname, args, exc)
             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
         if result is None:
-            return ''
+            return b''
         # get unicode on @htmlize methods, encoded string on @jsonize methods
         elif isinstance(result, text_type):
             return result.encode(self._cw.encoding)

More information about the cubicweb-devel mailing list