Preserve primary key when loading models#842
Open
sakshichitnis27 wants to merge 2 commits 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.
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
Narrow change to
get()hydration only; uses the samepkalready passed to the API and is covered by targeted tests. Stored PK values in the document, if present, would be overwritten by the requested key—intended for legacy missing-PK data.Overview
HashModel.getandJsonModel.getnow set the primary key from the lookup argument when Redis returns a document that omits the PK field (e.g. legacy hashes/JSON withoutpkstored).Before validation, the loaders merge
{cls._meta.primary_key.name: pk}into the fetched payload on both the normal and byte-decode paths for hashes, and on the JSON path forJsonModel. Custom primary keys (e.g.external_id) use the configured field name, so.pkand the custom field stay aligned with the key used inget(pk).New async tests in
tests/test_primary_key_loading.pycover missing-PK hash/JSON documents, undecoded hash bytes, and a customField(primary_key=True).Reviewed by Cursor Bugbot for commit bc45387. Bugbot is set up for automated code reviews on this repo. Configure here.