Skip to content

Python: remove unused index - #17008

Merged
JinHai-CN merged 5 commits into
infiniflow:mainfrom
JinHai-CN:fix556
Jul 16, 2026
Merged

JinHai-CN merged 5 commits into
infiniflow:mainfrom
JinHai-CN:fix556

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

Summary

Remove below indexes.

idx_tenant_langfuse_secret_key
idx_tenant_langfuse_public_key
idx_tenant_langfuse_host

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Tenant index cleanup

Layer / File(s) Summary
Drop tenant indexes
api/db/db_models.py
Adds best-effort removal for three tenant_langfuse indexes during migration.

Redis client type migration

Layer / File(s) Summary
Rename Redis API types
internal/engine/redis/redis.go
Replaces RedisClient and RedisMsg with Client and Message across Redis wrappers, streams, locks, and token buckets.
Update Redis integrations and tests
internal/agent/..., internal/service/..., internal/engine/redis/redis_test.go
Updates dependent service signatures, synonym interfaces, mocks, and strict token-bucket tests.

Admin updates

Layer / File(s) Summary
Centralize username handling
internal/admin/handler.go, internal/admin/handler_ee.go
Adds shared base64 username decoding and validation for standard and enterprise user-scoped handlers.
Tenant initialization and administration handling
internal/admin/service.go
Refines tenant model initialization, model token selection, administration errors, and MinIO verification setup.
Align admin responses and documentation
internal/admin/handler.go, internal/admin/service.go, internal/admin/service_ee.go
Updates variable error routing, Swagger annotations, and admin comments.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested labels: ☯️ refactor

Poem

A rabbit renames Redis with care,
Drops three indexes from the air.
User names decode,
Admin paths unload,
While tidy migrations hop everywhere.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is relevant to the main index-removal change, though it undersells the broader refactors in the PR.
Description check ✅ Passed The description matches the required Summary section and clearly states the index removals.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 16, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 16, 2026 11:14
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 101155b and 9a323e4.

📒 Files selected for processing (1)
  • api/db/db_models.py

Comment thread api/db/db_models.py
Comment on lines +1459 to +1465
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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]>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 16, 2026
Signed-off-by: Jin Hai <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a323e4 and 06cbe4b.

📒 Files selected for processing (10)
  • internal/admin/service.go
  • internal/admin/service_ee.go
  • internal/agent/audio/model_provider_synthesizer.go
  • internal/engine/redis/redis.go
  • internal/engine/redis/redis_test.go
  • internal/service/connector_box_oauth_test.go
  • internal/service/dataset.go
  • internal/service/nlp/synonym.go
  • internal/service/nlp/synonym_test.go
  • internal/service/oauth_login.go

Comment on lines +272 to 274
func (r *Client) IsAlive() bool {
return r.client != nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.

Suggested change
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 06cbe4b and 9d6ae3e.

📒 Files selected for processing (3)
  • api/db/db_models.py
  • internal/admin/handler.go
  • internal/admin/handler_ee.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/db/db_models.py

Comment thread internal/admin/handler.go
Comment on lines 268 to +271
if username == "" {
common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return "", err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (4518a58) to head (9d6ae3e).
⚠️ Report is 34 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 7c698f8 into infiniflow:main Jul 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant