Skip to content

fix(dashboard): filter numeric values correctly - #33230

Closed
suraj-mandal wants to merge 9 commits into
apache:masterfrom
suraj-mandal:master
Closed

fix(dashboard): filter numeric values correctly#33230
suraj-mandal wants to merge 9 commits into
apache:masterfrom
suraj-mandal:master

Conversation

@suraj-mandal

@suraj-mandal suraj-mandal commented Apr 24, 2025

Copy link
Copy Markdown

SUMMARY

The following changes have been made:

Upon debugging the models.py file, it was observed that the integer values were not being converted to float, which led to a mismatch among values.

Screenshot of the correct changes after the fix

image

ADDITIONAL INFORMATION

  • Fixes Incorrect filtering for numeric values with different decimal precision #33206
  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade are tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

fix(dashboard): filter numeric values correctly
@dosubot dosubot Bot added the dashboard Namespace | Anything related to the Dashboard label Apr 24, 2025

@korbit-ai korbit-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Error Handling Redundant numeric casting fallback ▹ view ✅ Fix detected
Files scanned
File Path Reviewed
superset/connectors/sqla/models.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment thread superset/connectors/sqla/models.py Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

@suraj-mandal suraj-mandal left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the fix

Comment thread superset/connectors/sqla/models.py Outdated
@suraj-mandal

Copy link
Copy Markdown
Author

rusackas, I have created the PR that fixes the issue. Can you kindly check and let me know if the checks are successful, since I am not able to test them on my own. Locally I ran the pre-commit hook and it was successful.

@codecov

codecov Bot commented Apr 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.90%. Comparing base (76d897e) to head (5fc98ff).
⚠️ Report is 2405 commits behind head on master.

Files with missing lines Patch % Lines
superset/models/helpers.py 0.00% 4 Missing ⚠️
superset/connectors/sqla/models.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #33230       +/-   ##
===========================================
+ Coverage   60.48%   72.90%   +12.41%     
===========================================
  Files        1931      559     -1372     
  Lines       76236    40550    -35686     
  Branches     8568     4274     -4294     
===========================================
- Hits        46114    29564    -16550     
+ Misses      28017     9877    -18140     
+ Partials     2105     1109      -996     
Flag Coverage Δ
hive 47.08% <0.00%> (-2.07%) ⬇️
javascript ?
mysql 71.89% <54.54%> (?)
postgres 71.95% <54.54%> (?)
presto 50.83% <0.00%> (-2.98%) ⬇️
python 72.87% <54.54%> (+9.36%) ⬆️
sqlite 71.49% <54.54%> (?)
unit 100.00% <ø> (+42.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@michael-s-molina

Copy link
Copy Markdown
Member

Possible duplicate of #33222

@suraj-mandal

Copy link
Copy Markdown
Author

I do think I have made a few more changes. Can you please verify once.

@rusackas

Copy link
Copy Markdown
Member

Running CI 🤞

@suraj-mandal

Copy link
Copy Markdown
Author

Resolving the changes and giving updated PR

@rusackas

Copy link
Copy Markdown
Member

Re-running

@suraj-mandal

suraj-mandal commented Apr 29, 2025

Copy link
Copy Markdown
Author

Hi, for the docker build failing, it is giving a response 429 - too many requests. Is it possible to rerun it? @rusackas

@suraj-mandal

Copy link
Copy Markdown
Author

Can someone help and approve it?

@rusackas

Copy link
Copy Markdown
Member

Not sure why CI got stuck, but I'll close and re-open this to kick-start the process.

@rusackas rusackas closed this Jul 15, 2025
@rusackas rusackas reopened this Jul 15, 2025

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, and I appreciate the test. Approving from my viewpoint, but I'm not quite sure if there are edge case risks associated with setting everything as float, so I'll ping @mistercrunch and @betodealmeida here in case they spot any risks... they can merge if not!

@suraj-mandal

Copy link
Copy Markdown
Author

Thanks @rusackas

@suraj-mandal

Copy link
Copy Markdown
Author

All checks have been success @rusackas

isinstance(value, (float, int))
and target_generic_type == utils.GenericDataType.NUMERIC
):
value = float(value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to explicitly convert a float to a float here?

# For backwards compatibility and edge cases
# where a column data type might have changed
try:
value = float(value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait there's a method right below (cast_to_num) that's attempting to do the same thing. I haven't looked into exactly what it does, but this feels like a patch-on-a-patch and we really need to move away from this type of layering here. My intuition says "let's get cast_to_num right and rely on it"

if operator == utils.FilterOperator.TEMPORAL_RANGE:
return value

if (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's long-standing issue where someone copied a bunch of methods/logic between the two files in this PR, and we really need to fix this ... @betodealmeida and myself have spoken about this and we're meaning to fix this once and for all. Not sure what exactly it means for this PR, but I'd say if we're going to fix a thing here let's dedup at least the method we're touching here (handle_single_value)

@mistercrunch

Copy link
Copy Markdown
Member

Can we clarify why we need to convert float->int? I read "which led to a mismatch among values.", but I'm unclear on what that means ... is this ordering/filtering-related?

@mistercrunch mistercrunch added the hold! On hold label Jul 15, 2025
@mistercrunch

mistercrunch commented Jul 15, 2025

Copy link
Copy Markdown
Member

Putting a hold for now as this part of the codebase is brittle and oddly layered, and with the premise that ints aren't floats and there might be intricacies around all this.

@suraj-mandal

Copy link
Copy Markdown
Author

all the numeric values were converted to float, because otherwise, it was found out that values were invariably truncated without explicitly converting them to float first.

@mistercrunch

Copy link
Copy Markdown
Member

all the numeric values were converted to float, because otherwise, it was found out that values were invariably truncated without explicitly converting them to float first.

Not sure if I understand what that means... So first converting float to float is a no-op, but converting int-to-float somehow addresses something here (?) What is it? Feels we should dig and address deeper.

@betodealmeida

Copy link
Copy Markdown
Member

Upon debugging the models.py file, it was observed that the integer values were not being converted to float, which led to a mismatch among values.

Can you give an example of the problem?

@betodealmeida

Copy link
Copy Markdown
Member

We most likely do not want to convert integers to floats, especially if they're being used in a comparison. Big integers are often used as IDs, and if they're are converted to floats they lose precision and become a different ID:

>>> i = 2**53 + 1
>>> i
9007199254740993
>>> float(i)
9007199254740992.0

@suraj-mandal

Copy link
Copy Markdown
Author

Consider the values [21, 21.8]. Without converting them to float, the code was considering both these values as same and thereby both of them were getting same values, which is not correct. So if there was an entry corresponding to 21 and an entry corresponding to 21.8, then the value corresponding to 21.8 was being shown by the value corresponding to 21.

@mistercrunch

mistercrunch commented Jul 15, 2025

Copy link
Copy Markdown
Member

Without converting them to float, the code was considering both these values as same and thereby both of them were getting same values, which is not correct.

Curious on the exact issue, so some part of the code is having issues handling ints (?) Sounds like a pretty specific thing, where we have mixed arrays of floats and ints maybe (?), and, presumably, something that doesn't do well with mixed-type arrays? Or maybe there's logic some place that looks at the type of the first value in the array and converts the whole array to that type?

@mistercrunch

Copy link
Copy Markdown
Member

About the duplicated logic across the two files. I finally got around to clean up this mess here #34177

@mistercrunch

Copy link
Copy Markdown
Member

Oh, found the issue reference in the PR body. Btw sorry if my comments come across poorly - I'm upset about the issue I address in #34177 and clearly that's not related to this PR in any way ...

Let's do this right, turns out to be more intricate than we had thought originally when issue was labeled as a "good first issue".

Let's try to understand what exactly isn't playing nice with types and address it at the core. Happy to help get to the bottom of it.

@mistercrunch

Copy link
Copy Markdown
Member

Looking at filter_values_handler, and more specifically at cast_to_num, it appears that method tries its best to convert numeric values (float,int,str) to a number, which seems kind of fine, and means we can end up in an array of mixed types. My guess it that something downstream in logic doesn't play nice with mixed-type arrays. Not sure what exactly, requires more digging ....

@betodealmeida

Copy link
Copy Markdown
Member

Consider the values [21, 21.8]. Without converting them to float, the code was considering both these values as same and thereby both of them were getting same values, which is not correct.

Thanks! In this case, to correct solution is making sure that the comparison is done correctly without having to change the values. Why is the code considering 21 == 21.8? Do you know the place where this comparison happens?

@suraj-mandal

Copy link
Copy Markdown
Author

I did a debug point of this. I will check it once and let you know.

@rusackas

rusackas commented Aug 5, 2025

Copy link
Copy Markdown
Member

@suraj-mandal just checking in. It seems there's a conflict to resolve/rebase, but hopefully we can keep pushing this forward :)

@suraj-mandal

Copy link
Copy Markdown
Author

Sure

@suraj-mandal

Copy link
Copy Markdown
Author

Will resolve the conflicts and start update the PR accordingly

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

Labels

dashboard Namespace | Anything related to the Dashboard hold! On hold size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect filtering for numeric values with different decimal precision

5 participants