-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users to define a new primary key. #347
Conversation
Signed-off-by: wiseaidev <[email protected]>
Signed-off-by: wiseaidev <[email protected]>
Signed-off-by: wiseaidev <[email protected]>
Signed-off-by: wiseaidev <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #347 +/- ##
==========================================
+ Coverage 77.64% 78.41% +0.76%
==========================================
Files 14 14
Lines 1154 1158 +4
==========================================
+ Hits 896 908 +12
+ Misses 258 250 -8
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: wiseaidev <[email protected]>
Signed-off-by: wiseaidev <[email protected]>
if separator_char in value: | ||
if isinstance(value, int): | ||
# This if will hit only if the field is a primary key of type int | ||
result = f"@{field_name}:[{value} {value}]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly (and painfully) enough, I've reach enough things recently to accept that we should probably start avoiding f-strings.
Let's not require it for this PR, but generally, we should remove them.
Super clean. Approved. |
Related to #251
Only 2 tests cases failed:
There could be another bug in the code when querying a primary key field of type int:
@dvora-h, any idea?
FYI, this PR is an enhancement on the
HashModel
, after merging this PR when all tests pass, users can now define a new primary key like:If it is not defined, it will take the default one:
Otherwise,
pk
will be removed, and you can access the new primary key using thekey
method.Edit:
For some reason, a primary key can't be indexed with an integer value, that's weird, Anyone knows why? Is this a thing in Redis?
Edit:
Found the bug, when the value is integer and the field is primary key, the field type become
RediSearchFieldTypes.TAG
rather than aRediSearchFieldTypes.NUMERIC
. To solve this issue, we can add an additional if statement within the this if statementelif field_type is RediSearchFieldTypes.TAG:
:Let's see if the tests pass this way.