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

Initializing python supabase client with timeout does not work as displayed on website. #487

Open
Simar-Kohli opened this issue Jul 5, 2023 · 3 comments

Comments

@Simar-Kohli
Copy link

Simar-Kohli commented Jul 5, 2023

Describe the bug
A clear and concise description of what the bug is.

I'm trying to set a timeout on the client (since i've been getting httpx read timeout errors).

import os
from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key, options={'timeout': 10})

This is as displayed on the website: https://supabase.com/docs/reference/python/initializing

To Reproduce
Steps to reproduce the behavior:
Put this code into a python file, and attempt to execute with current public pip3 install of supabase.

Expected behavior
I expected it to be a valid client instance and start to use it for my python script. Instead, I get this error:

Traceback (most recent call last):
File "/Users/XXXXX/Desktop/XXXXXX/XXXXXX/deployableApprovals.py", line 27, in
supabaseClient: Client = create_client(SUPABASEURL, SUPABASEKEY, {'timeout': 10})
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/supabase/client.py", line 248, in create_client
return Client(supabase_url=supabase_url, supabase_key=supabase_key, options=options)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/supabase/client.py", line 61, in init
options.headers.update(self._get_auth_headers())
AttributeError: 'dict' object has no attribute 'headers'

Desktop (please complete the following information):

  • OS: macOS
@Simar-Kohli
Copy link
Author

I figured a workaround:

from supabase.lib.client_options import ClientOptions

clientOptions = ClientOptions(postgrest_client_timeout=999999)
supabaseClient: Client = create_client(SUPABASEURL, SUPABASEKEY, clientOptions)

Seems to solve the issue. Not sure if the website docs are out of date or maybe I'm still doing something wrong.

@Simar-Kohli
Copy link
Author

Well while this works on my local machine, this does not run on an EC2 instance. Would love some assistance

@jtewright
Copy link

I experienced this problem too, and found that in addition to setting postgrest_client_timeout when initiating the python client, you have to change the default statement_timeout for the correct role through the Supabase dashboard SQL Editor, as per https://supabase.com/docs/guides/database/postgres/configuration#changing-the-default-timeout.

Oddly, while my python client uses the service_role API key, I needed to alter the statement_timeout for the authenticated role (note: not the authenticator role). Is that expected?

Note also that after 360s the request will error with the message: The upstream server is timing out.

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

No branches or pull requests

2 participants