supabase / supabase-py

Python Client for Supabase. Query Postgres from Flask, Django, FastAPI. Python user authentication, security policies, edge functions, file storage, and realtime data streaming. Good first issue.
https://supabase.com/docs/reference/python
MIT License
1.71k stars 201 forks source link

Insert into non-existing table raises empty APIErrror #901

Closed bukacdan closed 2 months ago

bukacdan commented 2 months ago

Insert into non-existing table raises empty APIErrror

Description

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

silentworks commented 2 months ago

The library doesn't give any information beyond what PostgREST which is the underlying server gives. This change would need to be suggested to the PostgREST repo https://github.com/PostgREST/postgrest.

silentworks commented 2 months ago

Closing this as it's a PostgREST issue and not a Supabase Python library issue.