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

Insert into non-existing table raises empty APIErrror #3697

Open
bukacdan opened this issue Aug 21, 2024 · 5 comments
Open

Insert into non-existing table raises empty APIErrror #3697

bukacdan opened this issue Aug 21, 2024 · 5 comments
Labels

Comments

@bukacdan
Copy link

Insert into non-existing table raises empty APIErrror

Description

Found this bug while using Supabase client, where I originally opened this issue.

If client.table("table_name") does not exist (e.g. typo), insert and upsert operations raise empty APIError.

To Reproduce

  1. Create reference to non-existing table
  2. Attempt to insert data
  3. Raises empty error with no information provided.
 def __init__(self, client: AsyncClient, user: AuthUser):
        self.client = client
        self.repository = self.client.table("not_existing_table")
        self.user = user

        try:
            insert_response = await self.repository.upsert(
                [mod.dict() for mod in db_models],
                count=CountMethod.exact,
                on_conflict="id",
                default_to_null=False,
            ).execute()
        except APIError as e:
            logger.error(f"Failed to bulk insert", user=self.user.id, **e.__dict__)
            # HERE the error is empty

Expected behavior

The error should contain information about the table not present in the scheme.

Screenshots

Screenshot 2024-08-18 at 23 36 41

System information

  • OS: macOS
  • Version of supabase-py: ^2.6.0
  • Version of postgrest: 0.16.9
  • Version of PostgreSQL: 15.6
@wolfgangwalther
Copy link
Member

Could you please reproduce this with a plain curl call, showing the actual PostgREST response, i.e. without any client/supabase involved?

@wolfgangwalther
Copy link
Member

Version of postgrest: 0.16.9

This is not a valid PostgREST version. Which version are you really using?

@bukacdan
Copy link
Author

bukacdan commented Aug 26, 2024

curl -H "apikey: $API_KEY" -H "Authorization: Bearer $API_KEY" "$DB_URL/rest/v1/non-existing-table"
{"code":"42P01","details":null,"hint":null,"message":"relation \"public.non-existing-table\" does not exist"}%

After trying to reproduce the issue with curl, I concluded that the error must be in the client code, not in PostgREST. Sorry for the false positive.

@bukacdan
Copy link
Author

curl -X POST -H "Content-Type: application/json" -H "apikey: $API_KEY" -H "Authorization: Bearer $API_KEY" "$DB_URL/rest/v1/non_existing_table" -d '{"name": "John Doe", "email": "john@example.com"}'
{}%

Actually I have to reopen this issue, it persists if I use POST on non-existing table.

PostgREST version: 12.x (not sure, using hosted supabase, but they've announced PostgREST 12 support)

@bukacdan bukacdan reopened this Aug 26, 2024
@wolfgangwalther
Copy link
Member

Confirmed against our spec fixtures:

% curl -X POST -H "Content-Type: application/json" "localhost:3000/items" -d '{"name": "John Doe", "email": "john@example.com"}'
{"code":"PGRST204","details":null,"hint":null,"message":"Could not find the 'email' column of 'items' in the schema cache"}

% curl -X POST -H "Content-Type: application/json" "localhost:3000/non_existing_table" -d '{"name": "John Doe", "email": "john@example.com"}'
{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants