Repository navigation
Python: remove unused index - #17008
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughAdds tolerant tenant index cleanup, renames Redis client and message types across dependent APIs, centralizes admin username decoding, and updates admin service initialization, errors, comments, and verification setup. ChangesTenant index cleanup
Redis client type migration
Admin updates
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/db/db_models.py`:
- Around line 1459-1465: Update alter_db_drop_index to reuse the existing narrow
handling for an absent index, while logging unexpected drop_index or migrate
failures and re-raising them so migrate_db cannot continue with a partial
schema. Remove the broad silent except behavior and the stale rename-related
comments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f24e924-88fd-46f9-9bdd-912fe5289f5c
📒 Files selected for processing (1)
api/db/db_models.py
| def alter_db_drop_index(migrator, table_name, index_name): | ||
| try: | ||
| migrate(migrator.drop_index(table_name, index_name)) | ||
| except Exception: | ||
| # rename fail will lead to a weired error. | ||
| # logging.critical(f"Failed to rename {settings.DATABASE_TYPE.upper()}.{table_name} column {old_column_name} to {new_column_name}, error: {ex}") | ||
| pass |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not silently swallow all index-drop failures.
This treats missing indexes, permission errors, SQL failures, and database outages identically, allowing migrate_db() to continue with a partially applied schema. Reuse the existing narrow missing-index handling, log unexpected failures, and re-raise them. Remove the stale rename-related comments as well.
As per coding guidelines, Python flows must add logging and stale commented-out code should be removed.
🧰 Tools
🪛 Ruff (0.15.21)
[error] 1462-1465: try-except-pass detected, consider logging the exception
(S110)
[warning] 1462-1462: Do not catch blind exception: Exception
(BLE001)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@api/db/db_models.py` around lines 1459 - 1465, Update alter_db_drop_index to
reuse the existing narrow handling for an absent index, while logging unexpected
drop_index or migrate failures and re-raising them so migrate_db cannot continue
with a partial schema. Remove the broad silent except behavior and the stale
rename-related comments.
Sources: Coding guidelines, Linters/SAST tools
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/engine/redis/redis.go`:
- Around line 272-274: Update Client.IsAlive and the other wrapper methods in
redis.go that access r.client, including Health, Exist, and Get, to guard both
the receiver and client before dereferencing them. Use the established r == nil
|| r.client == nil pattern from EvalTokenBucketStrict, preserving each method’s
existing behavior for unavailable clients.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e8b711a7-c702-4787-918c-82327c6c5225
📒 Files selected for processing (10)
internal/admin/service.gointernal/admin/service_ee.gointernal/agent/audio/model_provider_synthesizer.gointernal/engine/redis/redis.gointernal/engine/redis/redis_test.gointernal/service/connector_box_oauth_test.gointernal/service/dataset.gointernal/service/nlp/synonym.gointernal/service/nlp/synonym_test.gointernal/service/oauth_login.go
| func (r *Client) IsAlive() bool { | ||
| return r.client != nil | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add a nil-receiver guard to prevent panics.
If redis.Get() returns nil (which happens when Redis is not configured), calling redis.Get().IsAlive() will panic because the method checks r.client != nil but fails to verify r != nil.
Consider updating this method to handle r == nil safely. This risk also applies to the other wrapper methods in this file (such as Health, Exist, Get, etc.) where if r.client == nil is used. Updating them to if r == nil || r.client == nil (as you correctly did in EvalTokenBucketStrict) would prevent subtle crashes if callers ever forget to guard the client.
🛠️ Proposed fix for `IsAlive`
func (r *Client) IsAlive() bool {
- return r.client != nil
+ if r == nil {
+ return false
+ }
+ return r.client != nil
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (r *Client) IsAlive() bool { | |
| return r.client != nil | |
| } | |
| func (r *Client) IsAlive() bool { | |
| if r == nil { | |
| return false | |
| } | |
| return r.client != nil | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/engine/redis/redis.go` around lines 272 - 274, Update Client.IsAlive
and the other wrapper methods in redis.go that access r.client, including
Health, Exist, and Get, to guard both the receiver and client before
dereferencing them. Use the established r == nil || r.client == nil pattern from
EvalTokenBucketStrict, preserving each method’s existing behavior for
unavailable clients.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/admin/handler.go`:
- Around line 268-271: Update the empty-username branch in the handler to return
a non-nil error after calling common.ErrorWithCode, rather than returning the
prior err value that may be nil. Preserve the existing bad-request response and
ensure the caller halts before continuing with an empty username.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bde19944-eed5-4881-a319-cb763e47fdea
📒 Files selected for processing (3)
api/db/db_models.pyinternal/admin/handler.gointernal/admin/handler_ee.go
🚧 Files skipped from review as they are similar to previous changes (1)
- api/db/db_models.py
| if username == "" { | ||
| common.ErrorWithCode(c, common.CodeBadRequest, "Username is required") | ||
| return "", err | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Fix nil error return on empty username.
When username is empty, err is nil from the previous base64 decoding step. Returning "", err here will return nil for the error, causing the caller to continue executing the handler with an empty username, which can result in a double HTTP response and unexpected behavior.
Return a non-nil error instead so the caller correctly halts execution.
🐛 Proposed fix
if username == "" {
common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
- return "", err
+ return "", errors.New("username is required")
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if username == "" { | |
| common.ErrorWithCode(c, common.CodeBadRequest, "Username is required") | |
| return "", err | |
| } | |
| if username == "" { | |
| common.ErrorWithCode(c, common.CodeBadRequest, "Username is required") | |
| return "", errors.New("username is required") | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/admin/handler.go` around lines 268 - 271, Update the empty-username
branch in the handler to return a non-nil error after calling
common.ErrorWithCode, rather than returning the prior err value that may be nil.
Preserve the existing bad-request response and ensure the caller halts before
continuing with an empty username.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17008 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Remove below indexes.