Skip to content

🐛 fix: a stored null reads as null, not as the member's initializer - #18

Merged
edgarmesquita merged 3 commits into
masterfrom
fix/null-reads-as-null
Nov 18, 2026
Merged

edgarmesquita merged 3 commits into
masterfrom
fix/null-reads-as-null

Conversation

@edgarmesquita

Copy link
Copy Markdown
Contributor

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; } = 10 written null read 10 on every read.

  • RelationalMaterializer.Materialize (entity reads) and MaterializeByName (FromSqlAsync), RelationalRowBinder.Bind (QueryAsync into a result type) and CassandraMapper.Materialize write the null: null, or the type's default for a member that cannot hold null, as RelationalMapCompiler.CellSource already does for projections.
  • MongoDB and Cosmos DB already read the null. They get the same test.
  • The conventions guide says how a stored null reads.

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

  • StoredNullReadsAsNull on 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_too on PostgreSQL: FromSqlAsync and QueryAsync<Preset>.
  • Mutation: the relational tests and the Cassandra test fail on master's materializers.
  • Every suite passes locally: core 294, analyzers 19, PostgreSQL 205, MySQL and MariaDB 180, SQL Server 101, MongoDB 256, Cosmos DB 157, Cassandra 202.

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 it Quota, and the defect is #17.

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 edgarmesquita left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 edgarmesquita left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 edgarmesquita left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@edgarmesquita
edgarmesquita merged commit b9c4d6c into master Nov 18, 2026
12 of 13 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 7.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A stored null reads as the member's initializer on relational and Cassandra engines

2 participants