Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Conversation

@Nikdedov
Copy link
Contributor

Fixed the 'order' method for 'BaseSelectRequestBuilder' to support multiple sorting criteria and handle sorting on foreign tables.

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Issue: supabase/supabase-py#775

response = (
    supabase.table("clones")
    .select("*")
    .eq("owner", uid)
    .order("last_chatted", desc=True)
    .order("created_at", desc=True)
    .execute()
)

The problem is that adding several orders generates for QueryParams this: &order=last_chatted.desc&order=created_at.desc

Previous workaround:

request_build=
    supabase.table("clones")
    .select("*")
    .eq("owner", uid)
    .order("last_chatted", desc=True)
    .order("created_at", desc=True)

#get list of all added orders
removed_orders=request_build.params.get_list('order')

#remove them from QueryParams
request_build.params=request_build.params.remove('order')

#add back by merging them
request_build.params=request_build.params.add('order',','.join(removed_orders))
response =request_build.execute()

What is the new behavior?

response = (
    supabase.table("clones")
    .select("*")
    .eq("owner", uid)
    .order("last_chatted", desc=True)
    .order("created_at", desc=True)
    .execute()
)

Works as expected and generates QueryParams according to postgrest docs and it looks like: &order=last_chatted.desc,created_at.desc

Additional context

Add any other context or screenshots.

…ltiple sorting criteria and handle sorting on foreign tables.
@Nikdedov Nikdedov requested review from J0 and olirice as code owners August 19, 2024 20:05
@silentworks silentworks merged commit 97d520e into supabase:main Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants