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

argument must be a string, a bytes-like object or a number, not 'NoneType' #127

Open
evollution opened this issue Mar 14, 2020 · 7 comments

Comments

@evollution
Copy link

evollution commented Mar 14, 2020

@app.route("/data", methods=['GET'])
def data():
    columns = [
        ColumnDT(Customer.id),
        ColumnDT(Customer.Email),
    ]
    query = db.session.query(Customer)
    params = request.args.to_dict()

    
    rowTable = DataTables(params, query, columns)
    print(query , file=sys.stdout)
    return jsonify(rowTable.output_result())  

and i get error: Object of type Customer is not JSON serializable

@evollution
Copy link
Author

params
{'draw': '1', 'columns[0][data]': '0', 'columns[0][name]': '', 'columns[0][searchable]': 'true', 'columns[0][orderable]': 'true', 'columns[0][search][value]': '', 'columns[0][search][regex]': 'false', 'columns[1][data]': '1', 'columns[1][name]': '', 'columns[1][searchable]': 'true', 'columns[1][orderable]': 'true', 'columns[1][search][value]': '', 'columns[1][search][regex]': 'false', 'order[0][column]': '0', 'order[0][dir]': 'asc', 'start': '0', 'length': '10', 'search[value]': '', 'search[regex]': 'false', '_': '1584207848563'}

@evollution
Copy link
Author

{'draw': '1', 'recordsTotal': '13997', 'recordsFiltered': '13997', 'data': [{'0': <Customer#1>, '1': 1}, {'0': <Customer#2>, '1': 2}, {'0': <Customer#3>, '1': 3}, {'0': <Customer#4>, '1': 4}, {'0': <Customer#5>, '1': 5}, {'0': <Customer#6>, '1': 6}, {'0': <Customer#7>, '1': 7}, {'0': <Customer#8>, '1': 8}, {'0': <Customer#9>, '1': 9}, {'0': <Customer#10>, '1': 10}]}

This is the (rowTable.output_result() output

@evollution
Copy link
Author

evollution commented Mar 15, 2020

Another issue, because as item[0] is returned the query itself, item[-1] is missing :( @Pegase745 can you take a look why it returns item[0] as a query object instead of the first columnDT selected?

@westaytroy
Copy link

I had the same problem. Try using a query like in the example with select_from
query = db.session.query().select_from(Customer)
This worked for me. SOmehow the framework can't work with DB objects sadly.

@FrankyBoy
Copy link

heh, wish it was just db types ... "int() argument must be a string, a bytes-like object or a number, not 'NoneType'" ... hmmmm

@westaytroy
Copy link

heh, wish it was just db types ... "int() argument must be a string, a bytes-like object or a number, not 'NoneType'" ... hmmmm

This happens mostly if any of the values required are not set. I figured out that the framework assumes that at least "start" and "length" are set when init is called. my quick workaround for that:
params = request.args.to_dict() if "start" not in params: params["start"] = 0 if "length" not in params: params["length"] = -1
some error handling would have been nice here.

@FrankyBoy
Copy link

Good to know, thanks :) Maybe this should actually be a PR.

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

No branches or pull requests

3 participants