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

ArgumentException raised when updating nullable JObject with null #171

Open
justdmitry opened this issue Sep 19, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@justdmitry
Copy link

Bug report

Updating (via IPostgrestTable.Set) nullable JObject field with null value fails with ArgumentException (Expected Value to be of Type: JObject, instead received: .)

Inserts are Ok, only updates fail.

Steps to reproduce

Table structure (non-relevant fields skipped):

public.analytics (
  id bigint generated by default as identity not null,
  properties jsonb null
)

Model (non-relevant fields skipped):

[Table("analytics")]
public class Analytics : BaseModel
{
    [PrimaryKey("id")]
    public long Id { get; set; }

    [Column("properties")]
    public Newtonsoft.Json.Linq.JObject? Properties { get; set; }
}

Program code:

var client = new Supabase.Client(...);
JObject? properties = null;

var existing = await client.From<Analytics>()
    .Filter(x => /* some filtering here */)
    .Limit(1)
    .Single();
if (existing != null)
{
    await client.From<Analytics>()
        .Where(x => x.Id == existing.Id)
        .Set(x => x.Properties, properties)
        .Update();
}
else
{
    var item = new Analytics  { Properties = properties };
    await client.From<Analytics>().Insert(item);
}

Bottom code part (that handles Insert logic) works, but middle one (Update) does not: System.ArgumentException gets raised with Expected Value to be of Type: JObject, instead received: . message.

Expected behavior

Both code parts should work Ok.

System information

  • OS: Linux (Ubuntu)
  • NuGet package: Supabase, v1.1.1 and v1.0.5
  • Project .NET version: net8.0
  • Project nullable setting: enabled (<Nullable>enable</Nullable> in .csproj)
@justdmitry justdmitry added the bug Something isn't working label Sep 19, 2024
@justdmitry
Copy link
Author

Workaround: Replacing null value with empty object ({}) is a workaround, but empty object is not the same as NULL value...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant