Add update method and unify id attribute across all backends#316
Merged
Add update method and unify id attribute across all backends#316
Conversation
Contributor
|
Hi Mazen, I'll review the PR later but while we are at it can we take a look at this issue : Essentially I think rather initializing beanie with a single doc, we pass in multiple docs at init. |
Contributor
Author
Will make sure to support it in a different branch. Hopefully today. |
vik-rant
reviewed
Jan 5, 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.
Add Update Method and Unify ID Attribute Across All Backends
Summary
This PR adds the
updatemethod to all database backends and ensures consistentidattribute access across MongoDB, Redis, and Registry backends. This enables unified CRUD operations and eliminates the need for backend-specific ID handling in application code.Changes
1. Added
updateMethod to All BackendsImplemented
updatemethod across all ODM backends with both sync and async support:mongo_odm.py): Addedupdate()andupdate_sync()methodsredis_odm.py): Addedupdate()andupdate_async()methodsregistry_odm.py): Addedupdate()method supporting both legacyupdate(id, obj)and newupdate(obj)signaturesunified_odm.py): Addedupdate()andupdate_async()methods that route to the active backendmindtrace_odm.py): Added abstractupdate()method to the base classUsage:
2. Unified ID Attribute Access
Redis Backend
idproperty toMindtraceRedisDocumentthat mirrors thepkattributeidconsistently, eliminating the need to check forpkoridImplementation:
Registry Backend
idattribute is set on all returned documentsidis restored during retrievalidduringinsert()andupdate(), and restore it inget(),all(), andfind()Implementation:
insert(): Setsidon the document before storingupdate(): Setsidon the document (both legacy and new style)get(),all(),find(): Restoreidfrom the registry key since deserialization loses it3. Test Coverage
Example Usage
Before (Backend-Specific ID Handling)
After (Unified Interface)
Benefits
pkvsid- just usedoc.idMigration Guide
No migration needed - this is fully backward compatible. However, you can now:
Use
update()instead of manual save operations:Use
idattribute consistently: