fix: correct method names in hold_lock() context manager#2322
fix: correct method names in hold_lock() context manager#2322nightcityblade wants to merge 1 commit intotopoteretes:mainfrom
Conversation
Fix hold_lock() to call self.acquire_lock() and self.release_lock() instead of self.acquire() and self.release(), matching the abstract method definitions in CacheDBInterface. Fixes topoteretes#2304
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cognee/infrastructure/databases/cache/cache_db_interface.py (1)
37-46:⚠️ Potential issue | 🔴 CriticalRedisAdapter.hold_lock() still calls non-existent methods and must be fixed.
The interface fix is correct—
CacheDBInterface.hold_lock()now properly callsself.acquire_lock()andself.release_lock(). However,RedisAdapteroverrideshold_lock()(lines 187-195) and still callsself.acquire()andself.release(), which do not exist on the class. This will cause anAttributeErrorat runtime when using the Redis adapter.Per issue
#2304objectives, implementations must be consistent with the corrected interface. Apply the same fix to RedisAdapter:Fix for RedisAdapter.hold_lock()
In
cognee/infrastructure/databases/cache/redis/RedisAdapter.py:`@contextmanager` def hold_lock(self): """ Context manager for acquiring and releasing the Redis lock automatically. (Sync because of Kuzu) """ - self.acquire() + self.acquire_lock() try: yield finally: - self.release() + self.release_lock()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cognee/infrastructure/databases/cache/cache_db_interface.py` around lines 37 - 46, RedisAdapter.hold_lock still calls non-existent methods acquire() and release(); update the implementation to call the interface methods acquire_lock() and release_lock() instead. Locate the RedisAdapter class and modify its hold_lock() context manager to call self.acquire_lock() before yielding and self.release_lock() in the finally block, matching CacheDBInterface.hold_lock()’s behavior so the adapter implements the corrected interface.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@cognee/infrastructure/databases/cache/cache_db_interface.py`:
- Around line 37-46: RedisAdapter.hold_lock still calls non-existent methods
acquire() and release(); update the implementation to call the interface methods
acquire_lock() and release_lock() instead. Locate the RedisAdapter class and
modify its hold_lock() context manager to call self.acquire_lock() before
yielding and self.release_lock() in the finally block, matching
CacheDBInterface.hold_lock()’s behavior so the adapter implements the corrected
interface.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fae323c2-1314-4fd2-9aa4-1218989db550
📒 Files selected for processing (1)
cognee/infrastructure/databases/cache/cache_db_interface.py
Description
Fix
hold_lock()context manager inCacheDBInterfaceto callself.acquire_lock()andself.release_lock()instead ofself.acquire()andself.release(). The abstract methods are defined asacquire_lock()andrelease_lock(), so the current code would raiseAttributeErrorat runtime.Fixes #2304
Acceptance Criteria
hold_lock()callsself.acquire_lock()andself.release_lock()correctlyruff checkpassesType of Change
Screenshots
N/A
Pre-submission Checklist
DCO Affirmation
I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
Summary by CodeRabbit