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.73k stars 205 forks source link

httpx.ReadTimeout: timed out Supabase functions #814

Closed RedChops closed 3 months ago

RedChops commented 5 months ago

Feature request

Is your feature request related to a problem? Please describe.

When calling an Edge Function using client.functions.invoke(), if the function takes longer than 5 seconds to run I'll get a ReadTimeout exception

Describe the solution you'd like

I would like a way to configure the HTTPX timeout for Edge Function calls, the same way we can currently configure PostgREST and Storage. Or a way to supply a custom HTTPX client to supafunc-py

Describe alternatives you've considered

The following will let me create a client with a longer timeout, but it's accessing private interfaces:

supabase: Client = create_client(url, key, options=client_options)
func_headers = supabase.functions.headers
func_url = supabase.functions.url
timeout_client = utils.SyncClient(timeout=300.0, base_url=func_url, headers=func_headers, follow_redirects=True)
supabase.functions._client = timeout_client
silentworks commented 4 months ago

Have you tested the alternative you described and its working? I'm asking because looking at the edge functions limits the CPU time is 2 seconds which is less than the default 5 seconds. https://supabase.com/docs/guides/functions/limits#runtime-limits

RedChops commented 4 months ago

@silentworks I have, I've implemented this alternative in several scripts at this point. The CPU timeout is 2 seconds, yeah, but the total request timeout (according to the next line) is 150 seconds.

A lot of our edge functions themselves make network requests (main reason why we use them over plpgsql stored procedures really), so can take upwards of 30 seconds sometimes, depending.

silentworks commented 4 months ago

@RedChops thanks for getting back to me on this. I have added it to the Todo list and will try and get it added.