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

View Details: "is connected to:" uses wrong PK for query with join #34070

Closed
babakbh opened this issue Sep 23, 2023 · 2 comments · Fixed by #40874
Closed

View Details: "is connected to:" uses wrong PK for query with join #34070

babakbh opened this issue Sep 23, 2023 · 2 comments · Fixed by #40874
Assignees
Labels
.Frontend Priority:P2 Average run of the mill bug Querying/GUI Query builder catch-all, including simple mode .Team/QueryingComponents Type:Bug Product defects
Milestone

Comments

@babakbh
Copy link

babakbh commented Sep 23, 2023

Describe the bug

In some cases, after clicking on the "View Details", instead of showing the connected entities, the phrase "Unknown" is displayed.

image

By monitoring the messages passed between Metabase and the Postgres Docker Image using Wireshark, one can notice that the problem comes from a wrong sql query, that Metabase generates and sends to the Postgres Database:

Message generated by metabase and sent to the Postgres DB:
SELECT count(*) AS "count" FROM "source1"."rooms" WHERE "source1"."rooms"."h_id" = 9

The Reply message from Postgres DB to metabase:
operator does not exist: text = integer No operator matches the given name and argument types. You might need to add explicit type casts

Similar errors can be seen by checking the Wireshark log of discussions between metabase and the postgres DB after clicking on different columns data, every now and then.

To Reproduce

In order to reproduce this error,
1- start from the Destination Postgres Database from the following link:
https://github.com/ontopic-vkg/destination-tutorial

2- Add the destination database, as a source database to metabase,

3- join the following tables: Source1.Hospitality, Source1.Municipality.
image

4- after visualizing the data, and clicking on the "View Details" as follow,
image

one will get the following error message:
image

No response

Logs

By monitoring the messages passed between Metabase and the Postgres Docker Image using Wireshark, one can notice that the problem comes from a wrong sql query, that Metabase generates and sends to the Postgres Database:

Message generated by metabase and sent to the Postgres DB:
SELECT count(*) AS "count" FROM "source1"."rooms" WHERE "source1"."rooms"."h_id" = 9

The Reply message from Postgres DB to metabase:
operator does not exist: text = integer No operator matches the given name and argument types. You might need to add explicit type casts

Information about your Metabase installation

{
  "browser-info": {
    "language": "en-US",
    "platform": "Win32",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
    "vendor": "Google Inc."
  },
  "system-info": {
    "file.encoding": "UTF-8",
    "java.runtime.name": "OpenJDK Runtime Environment",
    "java.runtime.version": "11.0.18+10",
    "java.vendor": "Eclipse Adoptium",
    "java.vendor.url": "https://adoptium.net/",
    "java.version": "11.0.18",
    "java.vm.name": "OpenJDK 64-Bit Server VM",
    "java.vm.version": "11.0.18+10",
    "os.name": "Linux",
    "os.version": "5.10.102.1-microsoft-standard-WSL2",
    "user.language": "en",
    "user.timezone": "GMT"
  },
  "metabase-info": {
    "databases": [
      "h2",
      "postgres"
    ],
    "hosting-env": "unknown",
    "application-database": "h2",
    "application-database-details": {
      "database": {
        "name": "H2",
        "version": "1.4.197 (2018-03-18)"
      },
      "jdbc-driver": {
        "name": "H2 JDBC Driver",
        "version": "1.4.197 (2018-03-18)"
      }
    },
    "run-mode": "prod",
    "version": {
      "date": "2023-01-27",
      "tag": "v0.45.2.1",
      "branch": "release-x.45.2.x",
      "hash": "1a59de7"
    },
    "settings": {
      "report-timezone": null
    }
  }
}

Severity

Blocking the usage of metabase for us.

No response

Tasks

No tasks being tracked yet.
@babakbh babakbh added .Needs Triage Type:Bug Product defects labels Sep 23, 2023
@calherries
Copy link
Contributor

calherries commented Sep 27, 2023

Repro'd using the Sample database on v0.45.2.1, v0.46.6 and master.

The problem above with "View Details' happens more generally when one table is joined with another by a foreign key in a GUI question.

The POST /api/dataset request that is used to render the "... is connected to" section (the ObjectRelationships component) uses the row index in the table (starting from 0) to query the object relationships data. It should use the row's PK instead.

Steps to reproduce:

  1. Create a new question joining Accounts to Invoices.
image
  1. Visualize the results, open the browser network tab and click "View Details" on the third row of the results (the ID should be 1).
  2. In the payload of the latest POST /api/dataset request, observe that the filter in the query has the value 2, even though the ID of the Account is 1.
image
  1. Further, click one of the buttons under "Macy is connected to..."

image

  1. Observe that the filter applied to the Analytics table is "Account ID is 2", when it should be 1.
  2. You can try steps 2-5 again with the 4th row, and the same result will happen but instead the ID used in the filter is 3.
  3. On versions from 46 onwards, 'View Details' doesn't show any data at all when the dataset query doesn't find any results. You can reproduce this by going to the last result in the table, and clicking "View Details". You will see a blank modal with a loading spinner:
    image
    This is because the query includes a filter for an Account with ID=1999, which doesn't exist.

@calherries calherries changed the title View Details: Entity is connected to "Unknown" View Details: "is connected to:" uses wrong PK for query with join Sep 28, 2023
@luizarakaki luizarakaki added the Priority:P2 Average run of the mill bug label Oct 2, 2023
@ranquild ranquild added Querying/GUI Query builder catch-all, including simple mode and removed Visualization/Tables Raw, summarized, and pivoted tables labels Dec 15, 2023
@kamilmielnik
Copy link
Contributor

I can reproduce it in master at afc28b9.

uladzimirdev added a commit that referenced this issue Apr 3, 2024
uladzimirdev added a commit that referenced this issue Apr 3, 2024
* Map row id on object detail id

* Add a fallback

* Add e2e test

* Add a limit

* Provide a fix for #34070

* Simplify test
github-actions bot pushed a commit that referenced this issue Apr 3, 2024
* Map row id on object detail id

* Add a fallback

* Add e2e test

* Add a limit

* Provide a fix for #34070

* Simplify test
metabase-bot bot added a commit that referenced this issue Apr 3, 2024
* Map row id on object detail id

* Add a fallback

* Add e2e test

* Add a limit

* Provide a fix for #34070

* Simplify test

Co-authored-by: Uladzimir Havenchyk <125459446+uladzimirdev@users.noreply.github.com>
@uladzimirdev uladzimirdev added this to the 0.49.4 milestone Apr 3, 2024
rafpaf pushed a commit that referenced this issue Apr 3, 2024
* Map row id on object detail id

* Add a fallback

* Add e2e test

* Add a limit

* Provide a fix for #34070

* Simplify test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.Frontend Priority:P2 Average run of the mill bug Querying/GUI Query builder catch-all, including simple mode .Team/QueryingComponents Type:Bug Product defects
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants