Description
Bug report
Describe the bug
An exception occurs in Table<TModel> Where(Expression<Func<TModel, bool>> predicate)
if the predicate includes more than 2 or'ed conditions.
To Reproduce
Given the following model (and corresponding table in a Supabase project):
[Table("Contacts")]
public class Contact : BaseModel
{
[Column("first_name")]
public string FirstName { get; set; }
[Column("middle_name")]
public string MiddleName { get; set; }
[Column("last_name")]
public string LastName { get; set; }
}
Use of the following code:
string filter = "Ran";
var response = await supabase.From<Contact>().Where(c => c.FirstName.Contains(filter) || c.MiddleName.Contains(filter) || c.LastName.Contains(filter)).Get();
Results in the following PostgrestException exception:
Message:
{"code":"PGRST100","details":"unexpected \".\" expecting \"(\"","hint":null,"message":"\"failed to parse logic tree ((or.(first_name.like.*Ran*,middle_name.like.*Ran*),last_name.like.*Ran*))\" (line 1, column 6)"}
Source: "Supabase.Postgrest"
StackTrace:
at Postgrest.Helpers.<MakeRequest>d__3.MoveNext()
at Postgrest.Helpers.<MakeRequest>d__2`1.MoveNext()
at Concord.Services.SupabaseService.<GetContactsByName>d__33.MoveNext() in C:\Repos\Concord\Concord\Services\Supabase.cs:line 328
at Concord.ViewModels.MainViewModel.<SearchContacts>d__40.MoveNext() in D:\Repos\Concord\Concord\ViewModels\MainViewModel.cs:line 272
If the code is modified to use fewer or'ed conditions, such as in:
string filter = "Ran";
var response = await supabase.From<Contact>().Where(c => c.FirstName.Contains(filter) || c.LastName.Contains(filter)).Get();
The filter succeeds and behaves as expected.
It appears from the exception message that the underlying Postgrest code is improperly formatting the logic tree:
((or.(first_name.like.*Ran*,middle_name.like.*Ran*),last_name.like.*Ran*))
Perhaps it should have been:
((or.(first_name.like.*Ran*,middle_name.like.*Ran*,last_name.like.*Ran*)))
Expected behavior
The query should successfully select records whose first_name, middle_name, or last_name fields contain the specified filter string.
System information
- OS: iOS 17.0 simulator (also happens on Windows 11)
- Version of supabase-csharp: 0.14.0
Additional context
This is happening in a .NET MAUI application targeting iOS, Android, Windows, and mac Catalyst.