Skip to content

fix: register datasets inserted via MetaCache.upsert_many - #116

Merged
paulmueller merged 1 commit into
DCOR-dev:mainfrom
paulmueller-agent:fix-registry-org
Oct 22, 2026
Merged

paulmueller merged 1 commit into
DCOR-dev:mainfrom
paulmueller-agent:fix-registry-org

Conversation

@paulmueller-agent

Copy link
Copy Markdown
Contributor

Fixes a bug in the local metadata database (dbmodel/meta_cache.py) that I came across while adding type annotations in #114.

Bug

MetaCache._upsert_many_insert() updated the circle registry with

self._registry_org.setdefault(org_id, []).__add__(ds_ids)

list.__add__ returns a new list, which was discarded, so datasets inserted in bulk were never registered with their circle. The registry decides whether a dataset is new (upsert_dataset) and whether a circle has been seen before (upsert_many). Consequences within one DCOR-Aid session:

  • A second upsert_many() for the same circle, which is what the incremental CachedAPIInterrogator.update() does, treated all datasets as new and inserted them again. This fails with sqlite3.IntegrityError: UNIQUE constraint failed: kv_store.key.
  • upsert_dataset() for a dataset added via upsert_many() inserted a duplicate.

After a restart, the registry is rebuilt from the SQLite databases, so the problem only shows up when the database is updated more than once per session. The existing test_cache_upsert_many reopens the cache between the two upserts, which is why it didn't catch this.

Fix

.__add__(ds_ids) → .extend(ds_ids)

Tests

New tests in tests/test_dbmodel_meta_cache.py (offline), all failing before the fix:

  • test_cache_upsert_many_registry: the registry contains the inserted dataset IDs (was [])
  • test_cache_upsert_many_twice_same_session: updating a dataset and adding a new one in the same session (was IntegrityError); also checked after reopening
  • test_cache_upsert_dataset_after_upsert_many: no duplicate (was 6 datasets instead of 5)

All meta cache tests and the cached API interrogator tests pass locally against dcor-dev (39 passed).

🤖 Generated with Claude Code

`_upsert_many_insert` called `list.__add__` on the circle registry,
which creates a new list and discards it, instead of extending the
registry. As a consequence, a second `upsert_many` for the same circle
in the same session (incremental database update) inserted existing
datasets again and failed with `sqlite3.IntegrityError`, and
`upsert_dataset` inserted duplicates. The registry was only correct
after restarting DCOR-Aid, when it is rebuilt from the databases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paulmueller
paulmueller merged commit ad8a906 into DCOR-dev:main Oct 22, 2026
0 of 3 checks passed
@paulmueller-agent
paulmueller-agent deleted the fix-registry-org branch October 23, 2026 08:28
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.

2 participants