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

Filtering through foreign table doesn't respect join hint syntax #983

Open
notjustinshaw opened this issue Nov 1, 2024 · 8 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@notjustinshaw
Copy link

notjustinshaw commented Nov 1, 2024

I have a query in supabase-js that works, and when I translate it to supabase-py it doesn't work. I am on the latest version of each. From what I could gather while poking around, the python version doesn't seem to respect the join-hint PostgREST syntax for referencing tables with foreign keys.

Javascript

supabase
  .schema('pfr')
  .from('games')
  .select(`id,
    date,
    away_score,
    home_score,
    away_team:team_seasons!fk_away_team_id!inner(city, name),
    home_team:team_seasons!fk_home_team_id!inner(city, name),
  `)
  .ilike('away_team.name', awayTeam)
  .ilike('home_team.name', homeTeam);

Python

supabase
  .schema('pfr')
  .table('games')
  .select('''id,
    date,
    away_score,
    home_score,
    away_team:team_seasons!fk_away_team_id!inner(city, name),
    home_team:team_seasons!fk_home_team_id!inner(city, name),
  ''')
  .ilike('away_team.name', awayTeam)
  .ilike('home_team.name', homeTeam);

Schema

The schema is what you would expect; a games table with two foreign keys each pointing at a team_season.

Error Message

In PostgREST, you are supposed to be able to reference aliased foreign keys like this. It shouldn't assume the column is a column on the games table. Instead it should use the join-hint to compute a path to that table based on the constraints/keys available between the games table and team_seasons table (in this case, there are two paths: fk_home_team_id and fk_away_team_id).

APIError: {'code': '42703', 'details': None, 'hint': None, 'message': 'column games.away_team.name does not exist'}
@notjustinshaw notjustinshaw added the bug Something isn't working label Nov 1, 2024
@silentworks
Copy link
Contributor

Please provide a reproducible example repo to test this in. The repo should include some data and a database schema.

@teodos

This comment was marked as off-topic.

@silentworks
Copy link
Contributor

@teodos this is not related and you should also provide your table details when posting. Your error is making reference to applications but your table is called applicants. Without seeing the tables we don't know what issue you could be having. Also open a separate issue with all the details I mentioned in this post.

@silentworks silentworks self-assigned this Nov 6, 2024
@teodos

This comment was marked as off-topic.

@silentworks
Copy link
Contributor

@teodos the docs clearly states how the .or_ operator works and you aren't following it's syntax. As I've mentioned before your issue is not related to the OPs issue, you should open your own issue and stop adding to this one.

@notjustinshaw
Copy link
Author

notjustinshaw commented Nov 8, 2024 via email

@silentworks
Copy link
Contributor

@notjustinshaw I tested the message example from the docs and didn't get any issue with it.

@silentworks
Copy link
Contributor

silentworks commented Nov 13, 2024

@notjustinshaw here is a screen recording of me testing the sample data you mentioned in the docs with the Python client.

Turn your volume down as I might be a bit loud when talking in the video.

supabase_py_983.mp4

@supabase supabase deleted a comment from salihselimsekerci Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants