-
Notifications
You must be signed in to change notification settings - Fork 236
Incorrect checking of JSONB null values #3511
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
Comments
This is the model I used:
|
Thanks, I agree this looks like a bug, but I can't see this happening with the minimal repro below. Can you help out by tweaking it to make it fail as it does for you? Attempted reproawait using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Users.Add(new User
{
Name = "John Doe",
MetaData = new UserMetaData() { DatabaseAccess = null }
});
await context.SaveChangesAsync();
context.ChangeTracker.Clear();
_ = context.Users.Where(m => m.MetaData.DatabaseAccess != null && m.MetaData.DatabaseAccess.Any()).ToListAsync();
public class BlogContext : DbContext
{
public DbSet<User> Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql("Host=localhost;Username=test;Password=test")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(user =>
{
user.OwnsOne(m => m.MetaData, m =>
{
m.ToJson();
m.OwnsMany(u => u.DatabaseAccess);
});
});
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public UserMetaData MetaData { get; set; } = new();
}
public class UserMetaData
{
public List<UserMetaDataDatabaseAccess>? DatabaseAccess { get; set; } = [];
}
public class UserMetaDataDatabaseAccess
{
public required string Instance { get; set; }
} |
Try running this query:
Both of these give this error:
It runs this query:
I have a repo here: https://github.com/rogerfar/npgsql-reproduction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I run this query:
It generates this query:
This is incorrect because if the values MetaData.DatabaseAccess is null, postgres cannot query it:
But, the statement
m.MetaData.DatabaseAccess != null
is ignored, there is no explicit null check.Important to note is that if you do in postgres:
It WILL return items that are
null
, it will only filter out items that do not have the key on theMetaData
column set.I believe the appropriate way to null check a value is:
Which makes the initial complete query:
The text was updated successfully, but these errors were encountered: