fix: correct storage.update() call signature in _update_active_counts()#280
Merged
MaojiaSheng merged 3 commits intovolcengine:mainfrom Feb 25, 2026
Merged
Conversation
_update_active_counts() was calling storage.update() with MongoDB-style keyword arguments (filter= and update=) that do not match the actual method signature: async def update(self, collection: str, id: str, data: Dict[str, Any]) This caused a TypeError on every session commit, silently swallowed by the except block, leaving active_count permanently at 0. Fix: use fetch_by_uri() to retrieve the record and its id, then call update(collection, id, data) with the correct positional semantics. Also adds a regression test that verifies active_count actually increments in storage after a commit with usage records.
- client._service doesn't exist on AsyncOpenViking; correct path is client._client.service.vikingdb_manager (using public .service property) - Expand regression test docstring to note both bugs fixed: 1. wrong kwargs (filter=/update=) → TypeError 2. $inc operator not supported by storage.update()
…active_counts
fetch_by_uri() filters on the 'uri' path-type field. The local VikingDB
engine applies hierarchical (subtree) matching to path fields, so querying
uri='viking://resources/doc' also returns child records such as
'viking://resources/doc/chunk1'. When more than one record matches,
fetch_by_uri raises ValueError('Duplicate records found') and returns None,
leaving active_count un-updated even after the TypeError fix.
Fix: compute record_id = md5(uri) directly (the same formula used in
collection_schemas.py) and call storage.get(ids=[record_id]), which is an
exact ID lookup and is unaffected by path-field matching semantics.
Also updates the regression test to use storage.get() for the same reason.
zhoujh01
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Session._update_active_counts()has three bugs that leaveactive_countpermanently stuck at 0.Bug 1: wrong keyword argument names
Python raises
TypeError: update() got an unexpected keyword argument 'filter'on every call. The exception is silently swallowed byexcept Exception, soactive_countis never written.Bug 2: unsupported
$incoperatorstorage.update()is merge-and-upsert ({**existing, **data}). It does not support MongoDB-style increment operators. The value must be a plain integer.Bug 3:
fetch_by_urireturns subtree matches on path fieldsEven after fixing bugs 1 and 2, using
fetch_by_uri()to locate the record is unreliable. The local VikingDB engine applies hierarchical (subtree) matching topath-type fields, so filteringuri = 'viking://resources/doc'also matches child records like'viking://resources/doc/chunk1'. When more than one record matches,fetch_by_uriraisesValueError("Duplicate records found")and returnsNone—active_countstill goes unupdated.Verified empirically:
Fix
Compute
record_id = md5(uri)directly — the same formula used incollection_schemas.pyfor every context record — then usestorage.get(ids=[record_id])for a precise single-record lookup unaffected by path-field matching semantics:Verification
All three bugs independently verified (3/3 runs each):
TypeError: update() got an unexpected keyword argument 'filter'update()implementation confirmed as merge, no$incsupportmustop returns subtrees, not exact matchesEnd-to-end test result before fix (3/3 runs):
Changes
openviking/session/session.py: addimport hashlib; replace broken kwargs +$inc+fetch_by_uriwithstorage.get(ids=[md5(uri)])lookup and correctupdate(id, data)calltests/session/test_session_commit.py: add regression test usingstorage.get()for exact id lookup; docstring covers all three bugs