Skip to content

A relationship is compared by its related IDs: =~ null is an empty set (v1.34.0) - #205

Merged
gmpassos merged 9 commits into
masterfrom
fix/relationship-in-null
Nov 8, 2026
Merged

gmpassos merged 9 commits into
masterfrom
fix/relationship-in-null

Conversation

@gmpassos

@gmpassos gmpassos commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

On a relationship field, =~ / !~ now treat null as an empty set of IDs, and == / != treat [] like null. This applies to a to-one (an entity or an EntityReference) and to a to-many (a List of entities or an EntityReferenceList), on every DB adapter.

Query Before Now
store =~ null, =~ [null], =~ ? with null IS NULL (no related entity) none, same as =~ []
store !~ null IS NOT NULL all, same as !~ []
store =~ [1, null] IN (1) OR IS NULL IN (1)
stores == [], != [] SQL: IS NULL / IS NOT NULL; memory: none / all without / with related entities (as == null / != null) on both
owner == ? with [] memory: an error as == null

Unchanged:

  • non-relationship fields: number =~ null is still IS NULL;
  • paths through a relationship: store.name =~ null, roles.type == null;
  • store == null / store != null.

Tests: a new shared DB test, Relationship operators: by ID, on every adapter, computes the expected results from a model of each entity's related IDs. Each case is also checked through !(...).

  • =~ / !~ with [], null, [null], an ID, [id], [id1, id2] and [id, null], each as a literal, a ? parameter and a ?:name parameter. Entities as parameters too.
  • == / != with null, [] and IDs.
  • Fields: Address.closedStores (EntityReferenceList), Address.stores (List), Store.owner (entity) and User.userInfo (EntityReference).

Local results: memory (+256) and SQLite (+224) pass, as do the condition, encoder and SQL unit tests. PostgreSQL, MySQL and the full suite run in CI.

🤖 Generated with Claude Code

…t (v1.34.0)

- =~/!~ with null (a null parameter, [null]) on a relationship field
  (to-one entity/EntityReference, to-many List/EntityReferenceList) is an
  empty set of IDs, as []: =~ matches none, !~ all (was IS NULL / IS NOT
  NULL); a null in the list is ignored. Memory and SQL.
- ==/!= with [] on a relationship is as with null (memory matched none/all).
- Fix: `store == ?` with [] resolved [] as an entity ID (memory error).
- KeyCondition.isRelationshipKey (cached per entity handler).
- Tests: 'Relationship operators: by ID, on every adapter', expectations
  from a model of each entity's related IDs, over closedStores, stores,
  owner and userInfo; owner =~ null updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.85%. Comparing base (1f67fc2) to head (e0c6729).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #205      +/-   ##
==========================================
+ Coverage   95.83%   95.85%   +0.01%     
==========================================
  Files          75       75              
  Lines       26359    26519     +160     
==========================================
+ Hits        25261    25419     +158     
- Misses       1098     1100       +2     
Flag Coverage Δ
unittests 95.85% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

gmpassos and others added 8 commits November 8, 2026 02:45
…(any field)

- x =~ null / x =~ ? with null: none, as x =~ [] (was IS NULL); !~: all.
  KeyConditionINBase.valuesAsList(null) is []; a single null parameter
  is an empty set (memory and SQL).
- x == [] / != [] (also a parameter []): as == null / != null, for any
  field (memory matched none/all; SQL already IS NULL / IS NOT NULL).
- An explicit null element (=~ [null], [3, null]) still matches a null,
  except for a relationship (ignored: it never has a null ID).
- Tests updated and added: text, numbers, a to-one's and a to-many's
  fields; unit tests for the SQL and memory encodings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Ds; photo

- SQL _isRelationshipKey: by the field's declared type (as memory), not
  the DB's foreign keys (User.photo: a String ID without one).
- KeyCondition.isRelationshipType / isToManyType: a List of an entity type
  only (not a List of enums or other classes); used by isRelationshipKey
  and hasToManyInKeyPath.
- An EntityReference/EntityReferenceList parameter is compared by its
  ID(s) (memory and SQL).
- ==/!= with [x] is with x, and a reference with its ID (memory, as SQL):
  _equalsRightValue (replaces _isEmptyListValue).
- Encoder: an entity as a value of a String/int ID column is its ID (was
  its toString); a primitive value for an entity type is already an ID.
- Memory: a to-one stored by another adapter (Photo) keeps its ID when not
  found (was null: photo == null matched every user).
- Tests: photo, EntityReference/EntityReferenceList and Set parameters,
  == [id], &&/|| combinations; CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- == [v] / != [v] / =~ [v] / !~ [v] literals on a number and a text.
- A relationship's == ? / != ? with an entity parameter.
- A to-many relationship's count and limit/offset pages: each entity once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nresolved to-one

- ==/!= with a list on a list or binary field (List<String>, Uint8List):
  compared as a whole again (`[x]` as `x` only for other fields);
  `== []` is still IS NULL.
- Memory =~/!~ of a path ending in a reference (owner.userInfo =~ ?):
  references as parameters by their IDs, as SQL.
- Memory: a path through an unresolved to-one (another adapter's entity,
  a missing row): its ID field is the ID, other fields null (failed).
- Tests: list/binary == and != (unit), owner.userInfo with references,
  != ? with [id]; CHANGELOG: list fields, reference lists with ==, known
  difference (a String ID for an int ID), Markdown lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…null

- Encoder: a one-element list is unwrapped first (unless the field is a
  list or binary), so its enum is its name and its entity its ID (SQL
  compared their toString).
- Memory: == null / != null of a list field: a list is a value, also with
  a null element (was "any element null").
- Tests: an enum/entity in a one-element == ? list, roles.id == [],
  roles.type =~ ? with null, stores.number (=~ null, [null], == []), a
  list field with a null element (unit).
- CHANGELOG: the to-one path entry corrected (a missing row; a path through
  another adapter's entity isn't supported), == with a 2+ values list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its IDs subquery (id IN ( SELECT ... )) may not keep the table order
(PostgreSQL's hash semi-join): without an explicit order, ORDER BY id, as
its plain JOIN (and memory) returned it. Found running menu_ici_api's
tests on PostgreSQL (spot_module_test: selectEstablishmentsBySharedSpotID).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
db_users on memory, SQLite and PostgreSQL (one container), --repeat 5.
Memory and SQLite: the PR within noise of 1.32.1 (1.33.0's SQLite dip on
byState/list/count gone); PostgreSQL 1-9% lower, as count (none of the
changed code) is: the container's drift. Memory remove/count lower than
2026-10-14 on all three versions: older than these fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Encoder: the entity branch's `[]`/`[x]` unwrap is unreachable since the
  unwrap at the top (removed). SQL: a relationship's IN with a non-list
  null is unreachable (=~ null is [], a lone null parameter an empty
  set; removed).
- Tests: an EntityReferenceList parameter on a path ending in a reference
  (owner.userInfo =~ ?), and a path through an unresolved to-one (its ID
  field the ID, other fields null).
- HISTORY: PostgreSQL A/B alternating 1.32.1 and the PR on one container:
  within 1.5% (the sequential runs' drop was the container's drift).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gmpassos
gmpassos merged commit 32e1dbf into master Nov 8, 2026
11 checks passed
@gmpassos
gmpassos deleted the fix/relationship-in-null branch November 8, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant