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

fix: fixed the 'order' method for 'BaseSelectRequestBuilder' #495

Merged
merged 4 commits into from
Aug 22, 2024

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 olirice and J0 as code owners August 19, 2024 20:05
@silentworks silentworks merged commit 97d520e into supabase:main Aug 22, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants