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

TypeError: unsupported operand type(s) for 'NoneType' and 'float' (using Queries) #180

Open
Mraimou opened this issue Apr 26, 2019 · 5 comments
Labels
bug no stale Use this label to prevent the automated stale action from closing this PR/Issue.

Comments

@Mraimou
Copy link

Mraimou commented Apr 26, 2019

Hello,
I'm using kpis in my report based on queries:
kpi1.expression: q1.field1
kpi2.expression: q2.field2
kpi3.expression: q1.field1 + q2.field2
I'm getting TypeError: unsupported operand type(s) for 'NoneType' and 'float' when a query returns None.
I noticed that in case of accounting expressions None is replaced by AccountingNone:
replaced_expr = aep.replace_expr(expression) => '(AccountingNone)'
val = mis_safe_eval(replaced_expr, locals_dict) => AccountingNone

but in case of queries:
replaced_expr==expression => q1.field1 + q2.field2
val = mis_safe_eval(replaced_expr, locals_dict) => #ERR

@sbidoul
Copy link
Member

sbidoul commented Apr 28, 2019

This should have been fixed in version 3.3.0. Which version are you using?

@Mraimou
Copy link
Author

Mraimou commented Apr 29, 2019

I'm using 3.3.0
do you mean this fix?
I noticed that's related to conversion between AccountingNone and other types & vice versa.
but in the error i'm getting, the problem is caused by 'NoneType' and 'float'

@sbidoul sbidoul added bug and removed question labels Apr 29, 2019
@sbidoul
Copy link
Member

sbidoul commented Apr 29, 2019

@Mraimou ah yes, I misread. So yes, this looks like a small bug.

You can probably work around it by writing (q1.field1 if q1.field1 is not None else AccountingNone) + q2.field2. Or (q1.field1 or 0.0) + q2.field2 if you don't care about nulls.

@Mraimou
Copy link
Author

Mraimou commented Apr 29, 2019

Yes, sounds good!
Thank you @sbidoul

@sbidoul sbidoul changed the title TypeError: unsupported operand type(s) for 'NoneType' and 'float' TypeError: unsupported operand type(s) for 'NoneType' and 'float' (using Queries) Jul 8, 2019
@github-actions
Copy link

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jan 23, 2022
@sbidoul sbidoul added no stale Use this label to prevent the automated stale action from closing this PR/Issue. and removed stale PR/Issue without recent activity, it'll be soon closed automatically. labels Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug no stale Use this label to prevent the automated stale action from closing this PR/Issue.
Projects
None yet
Development

No branches or pull requests

2 participants