Preserve primary key when loading models#842
Open
sakshichitnis27 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit eea94cf. Configure here.
bc45387 to
010fa7b
Compare
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.

Fixes #828
Summary
Preserve the requested primary key when loading HashModel and JsonModel records with a missing stored primary key.
Added tests for default and custom primary keys.
Testing
pytest -q tests/test_primary_key_loading.py tests_sync/test_primary_key_loading.pyNote
Low Risk
Small, read-path change in
get()with focused tests; behavior only affects records missing a stored PK and should not alter keys that already include one.Overview
HashModel.getandJsonModel.getnow inject the lookup key into the document before Pydantic validation when Redis returns a record without a stored primary key field (common for legacy data).The primary key field name comes from
cls._meta.primary_key.name, so defaultpkand customField(primary_key=True)fields both resolve correctly. The HashModel byte-decode fallback path sets the same field after decoding.New async tests cover missing stored PK for hash and JSON models, bytes responses, and a custom primary key.
Reviewed by Cursor Bugbot for commit 010fa7b. Bugbot is set up for automated code reviews on this repo. Configure here.