Skip to content

Postgrest - Where filter with nullable field doesn't work #61

Closed
@rhuanbarros

Description

@rhuanbarros

Bug report

Describe the bug

A call to the database using Where or Filter method with a nullable field throws the following exception:

**System.ArgumentException: Unable to parse the supplied predicate, did you return a predicate where each left hand of the condition is a Model property?**
   at Postgrest.Table`1[[MaterialeShop.Admin.Src.Dtos.ListaItem, MaterialeShop.Admin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Where(Expression`1 predicate)

If the field is not nullable it works fine.

To Reproduce

Example:

await client
            .From<ListaItem>()
            // .Filter(nameof(ListaItem.ListaId), Postgrest.Constants.Operator.Equals, id)
            // .Where(x => x.ListaId == id)
            // .Order(nameof(ListaItem.CreatedAt), Postgrest.Constants.Ordering.Ascending)
            // .Where(x => x.SoftDeleted == false)
            .Where(x => x.CreatedAt == DateTime.Now)
            // .Order(x => x.CreatedAt, Postgrest.Constants.Ordering.Ascending)
            .Get();

CreatedAt is defined as:

[Column("CreatedAt")]
public DateTime? CreatedAt { get; set; } = DateTime.Now;

Expected behavior

Filter as it already works with a not nullable field.

Project information

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
    <PackageReference Include="gotrue-csharp" Version="3.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.2" PrivateAssets="all" />
    <PackageReference Include="MudBlazor" Version="6.1.2" />
    <PackageReference Include="supabase-csharp" Version="0.7.1" />
    <!-- <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" /> -->
  </ItemGroup>

  <ItemGroup>
    <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
  </ItemGroup>

</Project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions