Repository navigation
Refactor : Allow search multiple datasets - #14685
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new ChangesMulti-Dataset Search Feature
Knowledge-Graph Endpoint Consolidation
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)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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/apps/services/dataset_api_service.py`:
- Around line 1146-1153: The loop over tenants currently breaks after appending
the first matching tenant_id, so tenant_ids can contain at most one entry;
remove the break and instead collect all tenant.tenant_id values where
any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id
in kb_ids) is True, and after the loop check if tenant_ids is empty and return
(False, "Only owner of datasets authorized for this operation.") when no tenants
matched; update the block using UserTenantService.query,
KnowledgebaseService.query, tenants, tenant_ids, and kb_ids accordingly.
🪄 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: 8a82b0fd-5632-4e80-98ac-213e1d994669
📒 Files selected for processing (5)
api/apps/restful_apis/dataset_api.pyapi/apps/services/dataset_api_service.pyapi/utils/validation_utils.pytest/testcases/test_http_api/common.pyweb/src/utils/api.ts
| tenant_ids = [] | ||
| tenants = UserTenantService.query(user_id=tenant_id) | ||
| for tenant in tenants: | ||
| if any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id in kb_ids): | ||
| tenant_ids.append(tenant.tenant_id) | ||
| break | ||
| else: | ||
| return False, "Only owner of datasets authorized for this operation." |
There was a problem hiding this comment.
Collect all dataset tenant IDs before retrieval
Line 1151 breaks after the first matched tenant, so tenant_ids contains at most one tenant even when kb_ids span multiple tenants. This can make multi-dataset search return incomplete results.
🔧 Proposed fix
- tenant_ids = []
- tenants = UserTenantService.query(user_id=tenant_id)
- for tenant in tenants:
- if any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id in kb_ids):
- tenant_ids.append(tenant.tenant_id)
- break
- else:
- return False, "Only owner of datasets authorized for this operation."
+ joined_tenant_ids = {tenant.tenant_id for tenant in UserTenantService.query(user_id=tenant_id)}
+ required_tenant_ids = {kb.tenant_id for kb in kbs}
+ if not required_tenant_ids.issubset(joined_tenant_ids):
+ return False, "Only owner of datasets authorized for this operation."
+ tenant_ids = list(required_tenant_ids)🤖 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/apps/services/dataset_api_service.py` around lines 1146 - 1153, The loop
over tenants currently breaks after appending the first matching tenant_id, so
tenant_ids can contain at most one entry; remove the break and instead collect
all tenant.tenant_id values where
any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id
in kb_ids) is True, and after the loop check if tenant_ids is empty and return
(False, "Only owner of datasets authorized for this operation.") when no tenants
matched; update the block using UserTenantService.query,
KnowledgebaseService.query, tenants, tenant_ids, and kb_ids accordingly.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14685 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? Refactor : Allow search multiple datasets 1. support /datasets/search 2. get rid of /graph/search, use /graph ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Refactoring
### What problem does this PR solve? Refactor : Allow search multiple datasets 1. support /datasets/search 2. get rid of /graph/search, use /graph ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Refactoring
What problem does this PR solve?
Refactor : Allow search multiple datasets
Type of change