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

Exception trying to jsonify decimal count #694

Open
tpow opened this issue Dec 5, 2018 · 2 comments
Open

Exception trying to jsonify decimal count #694

tpow opened this issue Dec 5, 2018 · 2 comments

Comments

@tpow
Copy link

tpow commented Dec 5, 2018

I'm trying to use flask-restless against an Informix database. Informix returns a decimal type for count. For example, "select count(id) as c1 from users" would return c1 as Decimal('26'). Because of this, flask-restless throws an exception when trying to create the JSON of num_results. I'm finding this against the 0.17 version.

Even though Informix returns a Decimal type for the count, it looks like it could be safely cast to an Int in the context of generating num_results. I see two possible files where this could be addressed: in the helpers.py in the count function the returns could be cast to int. Second option, and perhaps better, change views.py in the _pagination function where it looks up num_results = count... I added the cast as num_results = int(count...) in this file and that seems to fix the problem for Informix. It looks like the equivalent code for this is views/base.py in the 1.0.0 beta code. Based on skimming the code changes, this might be partially fixed by #363 when not using pagination, but the cast to int may still be helpful otherwise.

Based on researching this problem, it sounds like Oracle databases can also return Decimal types for count.

Tim

@reubano
Copy link
Contributor

reubano commented Apr 15, 2020

The issue is with Flask, see my SO answer.

@tpow
Copy link
Author

tpow commented May 1, 2020

I don't think so, but even if so, Flask-restless should handle the return data type.

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

2 participants