Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A TypeError happened with ujson.dumps imported and DEBUG set True #507

Open
furoxr opened this issue Aug 3, 2018 · 1 comment
Open

A TypeError happened with ujson.dumps imported and DEBUG set True #507

furoxr opened this issue Aug 3, 2018 · 1 comment

Comments

@furoxr
Copy link

furoxr commented Aug 3, 2018

With app.debug set True, and the module ujson imported, When I accessed the doc of api, a TypeError was raised.

In the representations.py, the code of importing dumps

from __future__ import unicode_literals, absolute_import

try:
    from ujson import dumps
except ImportError:
    from json import dumps

from flask import make_response, current_app

and the function output_json in the same file

def output_json(data, code, headers=None):
    '''Makes a Flask response with a JSON encoded body'''

    settings = current_app.config.get('RESTPLUS_JSON', {})

    # If we're in debug mode, and the indent is not set, we set it to a
    # reasonable value here.  Note that this won't override any existing value
    # that was set.
    if current_app.debug:
        settings.setdefault('indent', 4)

    # always end the json dumps with a new line
    # see https://github.com/mitsuhiko/flask/pull/1262
    dumped = dumps(data, **settings) + "\n"

    resp = make_response(dumped, code)
    resp.headers.extend(headers or {})
    return resp

ujson.dumps() accepts one arg, while json.dumps() accepts one or more. So, when the app.debug is true, dumps will receive two args, 'data' and 'settings', with settings = { 'indent' : 4 }.

Then TypeError: 'indent' is an invalid keyword argument for this function

@ziirish
Copy link
Collaborator

ziirish commented Apr 10, 2019

Hopefully this will be addressed with #589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants