Skip to content

Supabase client .schema() change persists accross all instructions instead of the current one #573

Closed
@Hamza5

Description

@Hamza5

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

The .schema() method from the (async) Supabase client sets the schema as default, affecting the whole application instead of changing the schema of the current query only.

To Reproduce

Steps to reproduce the behavior:

  1. Create a table called tasks in the default (public) schema.
  2. Setup the Supabase Queue extension to create the pgmq_public schema.
  3. Run the following code after filling in the correct credentials and environment variables according to your account.
import os
import asyncio
from supabase import create_async_client
from dotenv import load_dotenv

load_dotenv()


async def main():
    url = os.getenv("SUPABASE_URL")
    key = os.getenv("SUPABASE_KEY")
    client = await create_async_client(url, key)
    auth_response = await client.auth.sign_in_with_password({
        "email": "[email protected]", "password": "t3stP@55w0rd"
    })
    print(auth_response.model_dump_json())
    results = await client.table("tasks").select("*").execute()
    print(results)
    results = await client.schema("pgmq_public").rpc("read", {"queue_name": "browser_tasks"}).execute()
    print(results)
    results = await client.table("tasks").select("*").execute()
    print(results)


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

The code above should run without problems, but the second await client.table("tasks").select("*").execute() crashes with the following exception:

Traceback (most recent call last):
  File "/home/hamza/Data/Programming/browser-agents/supabase_test_schema.py", line 26, in <module>
    asyncio.run(main())
  File "/home/hamza/.pyenv/versions/3.11.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/hamza/.pyenv/versions/3.11.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hamza/.pyenv/versions/3.11.11/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/hamza/Data/Programming/browser-agents/supabase_test_schema.py", line 21, in main
    results = await client.table("tasks").select("*").execute()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hamza/Data/Programming/browser-agents/.venv/lib/python3.11/site-packages/postgrest/_async/request_builder.py", line 78, in execute
    raise APIError(r.json())
postgrest.exceptions.APIError: {'code': '42P01', 'details': None, 'hint': None, 'message': 'relation "pgmq_public.tasks" does not exist'}

As you can see, it is trying to find pgmq_public.tasks and not public.tasks even though I didn't specify the schema in that instruction, just like the first one. So, the schema change is not affecting one query, but it persists for all following instructions.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: Debian 12
  • Version of supabase-py: 2.13
  • Version of Python: 3.11

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions