Skip to content

Check a fragment's NodeId index on each database it is used on - #598

Merged
jasperblues merged 3 commits into
mainfrom
nodeid-used-on
Nov 27, 2026
Merged

jasperblues merged 3 commits into
mainfrom
nodeid-used-on

Conversation

@jasperblues

Copy link
Copy Markdown
Member

Closes #552

Until now, the unindexed-@NodeId warning checked a fragment only on the databases whose catalogs name it. A fragment catalogued for one database and saved to another was never warned of on the second, though every save there scans the label. This port of drivine4j#894 (drivine4j#858) closes that gap.

Each operation of an object manager now tells the check which database a fragment is used on, by the name the database is registered under, so a manager for default counts as its first registered database:

  • The operations are load_all, load, count, load_nearest, load_matching, save, create, update, delete, delete_all, save_all, patch and patch_all.
  • edges counts both nodes it matches by id, and the target class of load_related.
  • groups counts the fragment it groups.
  • A view counts its root, the targets of its relationships, those of its relationship fragments, and the views nested in it, a view nested in itself included.

A fragment is checked on a database it was used on, or wherever the existing catalog rule already checked it. So every warning given before is kept, and the databases a fragment is used on are added. A use on a database that an enforce has already listed is checked at once. A use on one not listed yet is checked when an enforce lists it.

After the first use on a database, a use costs one lookup, without the lock. The check never reads the store and never raises. With no SchemaManager, nothing changes. docs/07-schema.md describes the new rule.

Tests (tests/unit/test_node_id_index_check.py):

  • drivine4j's cases, ported: a fragment used before or after the listing is checked there, once per database. A fragment whose id an index serves is not warned of. A view checks its root and relationship fragments. Nested views, a self-nested view and a relationship fragment's target are all checked. A reset forgets where a fragment was used.
  • Each operation of a manager, of its edges and of its groups, on SQLite, on the async and sync API, through the manager for default. Removing any hook fails the test.
  • Two SQLite databases: a fragment catalogued for a and saved to b is warned of on both.
  • A use whose check fails is passed over, and is not paid for again. A use cached under the same identity for another model is not taken for this one. A class once used can still be garbage-collected. A manager whose database can't be named still runs its operation.

Unit: 3226 passed. Whole suite with Oracle (ORACLE_TESTS=true) on the final commit:

  • tests/integration: 4710 passed, 291 skipped, 7 xfailed, 1 xpassed, 0 failed
  • tests/sync_integration: 4640 passed, 290 skipped, 7 xfailed, 1 xpassed, 0 failed

Review: 3 passes, last CLEAN.

  • Pass 1 added tests for the cache's identity guard and for a used class still being garbage-collectable.
  • Pass 2 added a test for a manager whose database can't be named, and updated a stale docstring.
  • Pass 3 was CLEAN.

The unindexed-NodeId warning checked a fragment only on the databases whose catalogs name it. A fragment catalogued for
one database and saved to another was never warned of on the other, though every save there scans the label.

Each operation of an object manager now tells the check which database a fragment is used on, by the name it is
registered under: saves, loads, counts, searches, deletes, patches, edges and groups. A view counts its root, its nested
views and the targets of its relationship fragments. A use on a database already listed is checked at once, and one not
yet listed when an enforce lists it. After the first use on a database, a use costs one lookup, without the lock; it
never reads the store and never raises. As drivine4j#894 (drivine4j#858).
…s, and that a used class can still be collected (#552)
…, and say the catalogued rule's docs name used-on databases (#552)
@jasperblues
jasperblues merged commit c16b4f3 into main Nov 27, 2026
16 checks passed
@jasperblues jasperblues mentioned this pull request Nov 29, 2026
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.

Give a fragment's @NodeId a range index by default, and warn of one no index serves

1 participant