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

Between Dates filter behaves inconsistently based on whether the column is from a joined table or not #12872

Closed
scottbradybuckii opened this issue Jul 8, 2020 · 3 comments
Assignees
Labels
.Correctness Priority:P1 Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness Querying/MBQL Querying/Nested Queries Questions based on other saved questions Querying/Processor Querying/ .Reproduced Issues reproduced in test (usually Cypress) Type:Bug Product defects
Milestone

Comments

@scottbradybuckii
Copy link

Describe the bug
When adding a date filter between two dates (I am currently using Postgres), it will make the filter inclusive of the end date if the column is from the base table, but it will make it exclusive of the end date if the column is from a joined table.

Logs
No errors are generated

To Reproduce
Steps to reproduce the behavior:

  1. Add a date filter to a column on the base table of a Question that is between two dates
  2. Click on the "View the SQL" button for that Question
  3. Verify that the dates are inclusive - ie. if your filter is between 2020-07-06 -> 2020-07-08, then the query would looks something like:
    WHERE ("public"."line_items"."created_at" >= timestamp with time zone '2020-07-06 00:00:00.000Z' AND "public"."line_items"."created_at" < timestamp with time zone '2020-07-09 00:00:00.000Z')
  4. Add a join to the Question
  5. Change the same date filter to filter down based on a date column in the joined table
  6. Click on the "View the SQL" button for that Question
  7. Verify that the dates are now exclusive:
    WHERE "Transaction"."created_at" BETWEEN timestamp with time zone '2020-07-06 00:00:00.000Z' AND timestamp with time zone '2020-07-08 00:00:00.000Z'

Expected behavior
The inclusivity and exclusivity shouldn't change based on whether you are filtering a column from a base table or joined table

Screenshots
Inclusive from base table:
Screenshot from 2020-07-08 15-02-45
Screenshot from 2020-07-08 16-45-44

Exclusive from joined table:
Screenshot from 2020-07-08 15-02-57
Screenshot from 2020-07-08 16-46-29

Information about your Metabase Installation:

  • Your browser and the version: Chromium 81.0.4044.138
  • Your operating system: Manjaro
  • Your databases: Postgres
  • Metabase version: v0.35.4
  • Metabase hosting environment: Docker running on Ubuntu 16.04
  • Metabase internal database: H2

Severity
Moderately severe. We have been using Metabase for over a year now and just noticed it, but it is worrisome because we are putting together weekly financial reports and this off-by-one day error has messed up our reporting. We can train users to add an extra day to reports that are filtering based on a joined date, but if this bug gets fixed, then those reports will be off by a day.

@flamber flamber added .Correctness Priority:P1 Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness Querying/ Querying/Nested Queries Questions based on other saved questions and removed .Needs Triage labels Jul 9, 2020
@flamber
Copy link
Contributor

flamber commented Jul 9, 2020

I have a feeling that it's related to #10824 (and perhaps #11837).

Steps to reproduce

  1. Custom question > Sample Dataset > Products
  2. Join Products (let's call it JoinedProducts) again on ID = ID
  3. Filter by Products.CreatedAt between 04/15/2019-04/15/2019 - this will result in 1 row
  4. Filter by JoinedProducts.CreatedAt between 04/15/2019-04/15/2019 - this will result in 0 rows
  5. Summarize Count
    image
  6. Expected result 1, but getting 0
SELECT count(*) AS "count"
FROM "PUBLIC"."PRODUCTS"
LEFT JOIN "PUBLIC"."PRODUCTS" "Products" ON "PUBLIC"."PRODUCTS"."ID" = "Products"."ID"
WHERE (("PUBLIC"."PRODUCTS"."CREATED_AT" >= timestamp with time zone '2019-04-15 00:00:00.000+02:00'
   AND "PUBLIC"."PRODUCTS"."CREATED_AT" < timestamp with time zone '2019-04-16 00:00:00.000+02:00')
AND "Products"."CREATED_AT" BETWEEN timestamp with time zone '2019-04-15 00:00:00.000+02:00' AND timestamp with time zone '2019-04-15 00:00:00.000+02:00')

@rlotun rlotun added this to the 0.37.2 milestone Oct 21, 2020
@camsaul camsaul self-assigned this Oct 29, 2020
@nemanjaglumac nemanjaglumac added this to In progress in Cypress Testing Oct 29, 2020
nemanjaglumac added a commit that referenced this issue Oct 29, 2020
nemanjaglumac added a commit that referenced this issue Oct 30, 2020
* Add repro for #12872 (Between Dates filter behaves inconsistently based on whether the column is from a joined table or not)
@nemanjaglumac nemanjaglumac added the .Reproduced Issues reproduced in test (usually Cypress) label Oct 30, 2020
@nemanjaglumac
Copy link
Member

@camsaul since you're assigned to work on this issue, just a note that a repro has been made, and it should be unskipped and merged together with a fix.

@nemanjaglumac nemanjaglumac moved this from In progress to Unfixed Issue (but cypress repro has been made) in Cypress Testing Oct 30, 2020
@rlotun rlotun modified the milestones: 0.37.2, 0.37.3 Nov 16, 2020
@rlotun rlotun added this to x.37.2+ Bug Fixes (x.37.2: Nov 30) in 38 Product Pod Planning Nov 16, 2020
@rlotun rlotun modified the milestones: 0.37.3, 0.37.4 Dec 7, 2020
@camsaul
Copy link
Member

camsaul commented Dec 9, 2020

Fixed by #13991

@camsaul camsaul closed this as completed Dec 9, 2020
38 Product Pod Planning automation moved this from x.37.4+ Bug Fixes (x.37.4: Dec 14) to Closed Issues and PRs Dec 9, 2020
This was referenced Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.Correctness Priority:P1 Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness Querying/MBQL Querying/Nested Queries Questions based on other saved questions Querying/Processor Querying/ .Reproduced Issues reproduced in test (usually Cypress) Type:Bug Product defects
Projects
No open projects
38 Product Pod Planning
  
Closed Issues and PRs
Development

No branches or pull requests

6 participants