Skip to content

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

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

Closed
2 tasks done
Hamza5 opened this issue Feb 24, 2025 · 1 comment · Fixed by #575
Closed
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@Hamza5
Copy link

Hamza5 commented Feb 24, 2025

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
@Hamza5 Hamza5 added the bug Something isn't working label Feb 24, 2025
@grdsdev
Copy link
Contributor

grdsdev commented Feb 24, 2025

Hi @Hamza5 thanks for reporting this, will be investigating ASAP.

@grdsdev grdsdev transferred this issue from supabase/supabase-py Feb 24, 2025
@silentworks silentworks self-assigned this Feb 28, 2025
@silentworks silentworks linked a pull request Mar 2, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants