Repository navigation
🐛 fix: a stored null reads as null, not as the member's initializer - #18
Conversation
The relational materializers (entity reads, FromSqlAsync, QueryAsync into a result type) and the Cassandra mapper skipped a NULL cell, so a member the entity initializes read its initializer instead of what the row holds: an `int? Quota = 10` stored NULL read 10. They now write null, or the type's default for a member that cannot hold null, as projections already read it. MongoDB and Cosmos DB already behaved so; one scenario holds every engine. Closes #16
edgarmesquita
left a comment
There was a problem hiding this comment.
Secondary review, round 1 (Antigravity, Gemini 4 Argon Medium), because Copilot cannot be requested on this repository.
One finding, fixed in e37f54b. Nothing dismissed.
| [Test] | ||
| public async Task A_stored_null_reads_as_null_in_a_member_that_starts_with_a_value() | ||
| { | ||
| var preset = new Preset { Note = null, Quota = null, Enabled = null, Since = null }; |
There was a problem hiding this comment.
[medium] The Cosmos DB test wrote its rows in the empty partition, while every other test of the fixture writes in its own Partition, so the shared container lost the test's isolation.
Fixed in e37f54b: both rows are written in the test's Partition.
edgarmesquita
left a comment
There was a problem hiding this comment.
Secondary review, round 2 (Antigravity, Gemini 4 Argon Medium), because Copilot cannot be requested on this repository.
One finding, half real. The real half is fixed in e16f48d. The rest is dismissed: MongoDB and Cosmos DB already read a stored null as null, which their new tests prove with no change to their code, and RelationalRowBinder.Bind called ChangeValue before this PR, so its conversion of a non-null cell is unchanged.
| Assert.That(new object?[] { listed.Note, listed.Quota, listed.Enabled, listed.Since }, Is.All.Null); | ||
|
|
||
| var other = (await Repo<Preset, Guid>(check).GetAsync(kept.Id))!; | ||
| Assert.That((other.Note, other.Quota, other.Enabled), Is.EqualTo(("initial", (int?)10, (bool?)true))); |
There was a problem hiding this comment.
[medium] The row stored with its initializers untouched was checked for Note, Quota and Enabled but not for Since.
Fixed in e16f48d, in every engine's test: the check covers all four members.
edgarmesquita
left a comment
There was a problem hiding this comment.
Secondary review, round 3 (Antigravity, Gemini 4 Argon Medium), because Copilot cannot be requested on this repository.
No findings. This is the last round the review allows, and it closes here.
|
🎉 This PR is included in version 7.1.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #16. Part of eQuantic/equantic-space#761.
OpenSpec change: core-stored-null-reads-null.
What changes
A NULL a relational or Cassandra row holds was skipped when the row was materialized (
if (reader.IsDBNull(ordinal)) continue;,row.IsNull(name)), so a member the entity initializes read its initializer:int? Quota { get; set; } = 10written null read 10 on every read.RelationalMaterializer.Materialize(entity reads) andMaterializeByName(FromSqlAsync),RelationalRowBinder.Bind(QueryAsyncinto a result type) andCassandraMapper.Materializewrite the null:null, or the type's default for a member that cannot hold null, asRelationalMapCompiler.CellSourcealready does for projections.Requirement implemented
A stored null reads as null. Every engine reads a member whose stored value is null as
null, or as its type's default when the member cannot hold null, whatever the entity's initializer, by key, in a listing and, on the relational engines, through raw SQL.Version
A patch (7.1.1), the maintainer's decision: no signature changes. A consumer that read an initializer where the row held NULL now reads the null.
Tests
StoredNullReadsAsNullon PostgreSQL, MySQL, MariaDB and SQL Server, and the same test on MongoDB, Cosmos DB and Cassandra. Each writes an entity with its four initialized nullable members set to null and another left as it starts, then reads both by key and in a listing.A_stored_null_reads_as_null_through_raw_sql_tooon PostgreSQL:FromSqlAsyncandQueryAsync<Preset>.master's materializers.Writing the Cassandra test found a separate defect: a member named after a CQL reserved word (
Limit) makes the migration send[Limit], which Cassandra refuses. The test entity calls itQuota, and the defect is #17.