-
-
Notifications
You must be signed in to change notification settings - Fork 59
fix: use SelectRequestBuilder for rpc call #254
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
Conversation
@J0 @anand2312 can you take a look? |
@@ -76,24 +76,24 @@ def from_table(self, table: str) -> AsyncRequestBuilder: | |||
"""Alias to :meth:`from_`.""" | |||
return self.from_(table) | |||
|
|||
async def rpc(self, func: str, params: dict) -> AsyncFilterRequestBuilder: | |||
async def rpc(self, func: str, params: dict) -> AsyncSelectRequestBuilder: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any reason to use async for this function?
await (await client.rpc(...)).execute()
async def rpc(self, func: str, params: dict) -> AsyncSelectRequestBuilder: | |
def rpc(self, func: str, params: dict) -> AsyncSelectRequestBuilder: |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #254 +/- ##
=======================================
Coverage 91.63% 91.63%
=======================================
Files 24 24
Lines 1183 1183
=======================================
Hits 1084 1084
Misses 99 99
☔ View full report in Codecov by Sentry. |
Hi there @a5r0n! I'm also trying to use RPC calls with the postgres-py library -- I tried testing with your fork and called with the
When I look at the raw response that's being returned by PostgREST, it's just a raw value. For context, my function is an In order for functions like this to be compatible with this implementation of That's definitely doable (easier than always returning a table) - but it's still a bit of overhead just to accommodate the client. Would an alternative approach be, perhaps, to provide in addition to the Thoughts? |
Sorry for not getting to this earlier @a5r0n sorry but I don't think using the SelectRequestBuilder fixes the issue here (correct me if I'm wrong) |
from response perspective, there is 3 result types.
|
And I think functions can return None as well with |
My 2c for right now would be to at least provide the mechanism for returning the raw response (not the raw HTTP response - we can still call Right now I'm doing this as a workaround: def rpc_call(
supabase: SupabaseClient,
procedure: str,
params: dict = {},
type_: Optional[type[BaseModel]] = None
):
query = supabase.postgrest.rpc(
procedure,
orjson.loads(orjson.dumps(params)) # ensures json properly serialized for requests
)
data = query.session.request(
query.http_method,
query.path,
json=query.json,
params=query.params,
headers=query.headers,
).json()
if data:
if type_ and isinstance(data, dict):
return type_(**data)
elif type_ and isinstance(data, list):
return [type_(**o) for o in data]
return data Basic type responses (like int, string, etc) are still correctly parsed by Ultimately I could imagine a more sophisticated solution where you could define a remote procedure explicitly in your client (could use Pydantic types) where the inputs to the function could also be validated as well as the response types - but for now I think just making it so people can use stored procedures however they have them configured would be the simplest. |
@chrisgoddard the official supabase client is actually using a different library to invoke functions, did you try that? (https://github.com/supabase-community/functions-py) |
My understand is that is for edge functions - I'm talking about Postgres stored procedures. |
Sure, my mistake. |
@anand2312 |
I'm reluctant to merge because it doesn't really fix the issue at hand 😦 If I'm not able to come up with something better in the next day or two I guess I'll merge this |
@anand2312 @a5r0n Is there any update on this? Appreciate you guys working on this. I just built a bunch of stuff around the assumption that I Can use RPC calls and only now found out that this is broken on supabase-py/postgrest-py |
fixes #200