-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
fix(date_parser): fixed bug for advanced time range filter #31867
base: master
Are you sure you want to change the base?
fix(date_parser): fixed bug for advanced time range filter #31867
Conversation
There was a problem hiding this comment.
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 | Fix Detected |
---|---|---|
Insufficient Error Context ▹ view |
Files scanned
File Path | Reviewed |
---|---|
superset/utils/date_parser.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Current Korbit Configuration
General Settings
Setting Value Review Schedule Automatic excluding drafts Max Issue Count 10 Automatic PR Descriptions ❌ Issue Categories
Category Enabled Naming ✅ Database Operations ✅ Documentation ✅ Logging ✅ Error Handling ✅ Systems and Environment ✅ Objects and Data Structures ✅ Readability and Maintainability ✅ Asynchronous Processing ✅ Design Patterns ✅ Third-Party Libraries ✅ Performance ✅ Security ✅ Functionality ✅ Feedback and Support
Note
Korbit Pro is free for open source projects 🎉
Looking to add Korbit to your team? Get started with a free 2 week trial here
elif unit.lower() in broad_units: | ||
return "today" | ||
else: | ||
raise ValueError(f"Unknown unit: {unit}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insufficient Error Context
Tell me more
What is the issue?
The get_relative_base function's ValueError lacks context about the function and input values.
Why this matters
During debugging, it will be harder to identify where this error originated and what the valid input values should have been.
Suggested change ∙ Feature Preview
raise ValueError(f"get_relative_base: Unknown time unit '{unit}'. Expected one of {granular_units | broad_units}")
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #31867 +/- ##
===========================================
+ Coverage 60.48% 82.95% +22.47%
===========================================
Files 1931 540 -1391
Lines 76236 39176 -37060
Branches 8568 0 -8568
===========================================
- Hits 46114 32500 -13614
+ Misses 28017 6676 -21341
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Hey @alexandrusoare , thanks for taking care of this. I left a comment on the issue itself, but IMHO we should instead have a look at the library that's parsing the human readable dates here and see if there's something we can address there instead or if there's a limitation on such library etc. |
Hey @Antonio-RiveroMartnez , at first I was afraid of overcomplicating stuff as adding special queries for words like "prior", "start of" etc as well, and I tried to follow the trail to the exact issue. I think and I am not 100% sure, the library doesn't recognize correctly words like "start of", "end of", "last 2 minutes", once I saw that the error is related to the library, I decided to take care of things like this. But I will have a second look on the library and let you know what are my discoveries and thoughts |
if unit.lower() in granular_units: | ||
return "now" | ||
elif unit.lower() in broad_units: | ||
return "today" | ||
else: | ||
raise ValueError(f"Unknown unit: {unit}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the linter might complain here unless you do:
if unit.lower() in granular_units: | |
return "now" | |
elif unit.lower() in broad_units: | |
return "today" | |
else: | |
raise ValueError(f"Unknown unit: {unit}") | |
if unit.lower() in granular_units: | |
return "now" | |
if unit.lower() in broad_units: | |
return "today" | |
raise ValueError(f"Unknown unit: {unit}") |
r"^last\s+([0-9]+)\s+(second|minute|hour|day|week|month|year)s?$", | ||
lambda delta, | ||
unit: f"DATEADD(DATETIME('{_relative_start}'), -{int(delta)}, {unit})", # pylint: disable=line-too-long,useless-suppression | ||
r"^(start of|beginning of|end of)\s+(this|last|next|prior)\s+([0-9]+)?\s*(day|week|month|quarter|year)s?$", # pylint: disable=line-too-long,useless-suppression # noqa: E501 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably easier to understand the regular expression if you use re.VERBOSE
mode, something like:
pattern = re.compile(r"""
^
(start\ of|beginning\ of|end\ of) # Match the phrases 'start of', 'beginning of', or 'end of'
\s+ # One or more spaces
(this|last|next|prior) # Match time references
\s+ # One or more spaces
([0-9]+)? # Optional number
\s* # Optional whitespace
(day|week|month|quarter|year)s? # Match time unit with optional plural 's'
$
""", re.VERBOSE)
r"^next\s+([0-9]+)\s+(second|minute|hour|day|week|month|year)s?$", | ||
lambda delta, | ||
unit: f"DATEADD(DATETIME('{_relative_end}'), {int(delta)}, {unit})", # pylint: disable=line-too-long,useless-suppression | ||
r"^(this|last|next|prior)\s+([0-9]+)?\s*(second|minute|day|week|month|quarter|year)s?$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here.
Fixes #30592
SUMMARY
Fixed bug where Advanced Time Range filter showed wrong dates for queries like "last 2 minutes" , "start of next month", "end of next month" etc
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE -> "Last 2 minutes"
AFTER -> "Last 2 minutes"
BEFORE -> "Start of this month"
AFTER -> "Start of this month"
BEFORE -> "End of next month"
AFTER -> "End of next month"
BEFORE -> "Prior 2 minutes"
AFTER -> "Prior 2 minutes"
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION