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

Links do not work after adding check constraint to a table #3109

Closed
Tracked by #3144
domdomegg opened this issue Jul 28, 2023 · 4 comments · Fixed by #3243
Closed
Tracked by #3144

Links do not work after adding check constraint to a table #3109

domdomegg opened this issue Jul 28, 2023 · 4 comments · Fixed by #3243
Assignees
Labels
restricted: maintainers Only maintainers can resolve this issue type: bug Something isn't working user reported Reported by a Mathesar user work: backend Related to Python, Django, and simple SQL
Milestone

Comments

@domdomegg
Copy link

Description

It appears that tables with any check constraint (e.g. on an unrelated column) breaks the display of all links on that table.

The foreign key constraint is held by the underlying database, and the links are shown in the link panel on the sidebar. However, in the grid the cells just show the raw value rather than a dropdown.

Another clue: clicking table > advanced > constraints results shows the error 'Unable to fetch table constraints When making an XHR request, the server responded with an error, but the response body was not valid JSON.' Under the hood this corresponds with a 500 request to /api/db/v0/tables/22/constraints/?limit=500

500 response body

<!doctype html>
<html lang="en">
<head>
  <title>Server Error (500)</title>
</head>
<body>
  <h1>Server Error (500)</h1><p></p>
</body>
</html>

To Reproduce

Steps:

  1. Add a link column to a table in Mathesar OR in another tool, add a foreign key constraint and refresh the schema in Mathesar
  2. [at this point, if you view the table you should see the link as a dropdown]
  3. In another tool, add a constraint to any column in the table
  4. View the table in Mathesar: The links continue to display fine
  5. Refresh the schema in Mathesar
  6. View the table in Mathesar

Expected: The links display as before
Actual: The raw value of the links (e.g. the number for an integer id column) are shown

  1. In another tool, remove the constraint
  2. View the table in Mathesar: all the data will disappear. Adding a record also seems broken from this point, but under the hood the record is actually added.
  3. Refresh the schema in Mathesar
  4. View the table in Mathesar: all the data is present and link works correctly again

Video:

This is all mock data. Ignore bit where I try to add person_id manually at the beginning, this is force of habit 😅. Also, I add a record in the external tool but this is not necessary for reproduction (this is just meant to show the check constraint appears to work fine in other tools, and doesn't stop manipulating data there, so I don't think this is a problem with the other tool).

Screen.Recording.2023-07-28.at.16.24.24.-.264.mp4

Environment

  • OS: Host: macOS, but mathesar 0.1.2 is running inside a podman container. I don't think this is relevant though.
  • Browser: Google Chrome
  • Browser Version: 115.0.5790.114 (Official Build) (arm64)
  • Other info: Using postgres:14 container.
@domdomegg domdomegg added status: triage type: bug Something isn't working labels Jul 28, 2023
@kgodey kgodey added this to the Next release milestone Jul 28, 2023
@kgodey kgodey added user reported Reported by a Mathesar user work: backend Related to Python, Django, and simple SQL restricted: maintainers Only maintainers can resolve this issue and removed status: triage labels Jul 28, 2023
@kgodey
Copy link
Contributor

kgodey commented Aug 10, 2023

@mathemancer tagging you here since you're going to be working on better compatibility with existing DBs.

@mathemancer
Copy link
Contributor

mathemancer commented Aug 11, 2023

This appears to be because we're throwing an error when any constraint exists on the table that Mathesar doesn't understand, breaking the constraints endpoint. Thanks for reporting this @domdomegg !

@MrChadMWood
Copy link

Are there any workarounds? Besides implementing a trigger (costly on performance), CHECK constraint is the only way to implement mutually exclusive columns (e.g, foreign keys) in a table. Basically either/or relationships at the record level.

@Anish9901
Copy link
Member

@domdomegg & @MrChadMWood since the merging of #3243 you should be able to add CHECK & EXCLUSION constraints to a table, without breaking the core functionalities of Mathesar, this change will get rolled out with our next release 0.1.4 which would be within the next few weeks. You could try it out now if you decide to run the latest develop though.

However it is worth noting that, we are yet to figure out a way to effectively display these constraints within our app and therefore these constraints won't be visible in the constraints section even if they exist for a given table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
restricted: maintainers Only maintainers can resolve this issue type: bug Something isn't working user reported Reported by a Mathesar user work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants