Repository navigation
Fix: parse by somark in parser - #17355
Conversation
📝 WalkthroughWalkthroughThe PDF parser now recognizes tenant model IDs, resolves their provider and instance through tenant services, and normalizes them into the provider-qualified format used by downstream parsing logic. ChangesTenant-aware PDF parser configuration
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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
🧹 Nitpick comments (3)
rag/flow/parser/parser.py (3)
343-353: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd focused regression coverage for tenant parser selection.
Cover successful normalization into
@mineru,@paddleocr, and@somark, plus missing-provider/instance and cross-tenant rejection cases so the new branch cannot silently regress into Vision parsing.As per coding guidelines, “Preserve valid behavior with focused tests.”
🤖 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 `@rag/flow/parser/parser.py` around lines 343 - 353, Add focused regression tests for the tenant-model resolution branch in the parser, covering successful normalization to `@mineru`, `@paddleocr`, and `@somark`. Also cover missing provider or instance records and cross-tenant model references, asserting these cases do not fall through into Vision parsing and preserve the expected rejection behavior.Source: Coding guidelines
343-353: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd observability for the new resolution flow.
Successful normalization and invalid/missing tenant model configuration currently produce no log entry, making parser-selection failures difficult to diagnose. Add structured debug/info logging for resolution and warning/error logging before rejecting invalid configuration; do not log credentials.
As per coding guidelines,
**/*.py: Add logging for new flows.🤖 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 `@rag/flow/parser/parser.py` around lines 343 - 353, Add logging around the tenant-model resolution block in the parser flow: record successful normalization with non-sensitive identifiers, and emit warning or error logs when the tenant model, provider, or instance lookup/configuration is invalid before the parser selection rejects it. Use the module’s existing logger and ensure credentials or other sensitive configuration values are never logged.Source: Coding guidelines
346-350: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid a database lookup for every parser name.
This condition queries
TenantModelServicefor every non-empty value, including built-in methods such asdeepdoc,mineru,paddleocr, andsomark. Short-circuit known parser literals or provide a single optimized tenant-model resolver to avoid an unnecessary database round trip for every PDF.🤖 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 `@rag/flow/parser/parser.py` around lines 346 - 350, Update the raw_parse_method handling in the parser flow to recognize built-in parser literals such as deepdoc, mineru, paddleocr, and somark before calling TenantModelService.get_by_id. Short-circuit those known values so they do not trigger tenant-model, provider, or instance database lookups, while preserving the existing resolver behavior for non-built-in names.
🤖 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 `@rag/flow/parser/parser.py`:
- Around line 343-353: Update the tenant-model normalization block around
TenantModelService.get_by_id to use tenant-scoped lookups for the model and
provider, and validate that the resolved instance belongs to the model’s
provider and self._canvas._tenant_id. If model, provider, or instance resolution
is partial or invalid, raise the established configuration error instead of
leaving raw_parse_method unchanged; only normalize to the provider-qualified
name after all validations pass.
---
Nitpick comments:
In `@rag/flow/parser/parser.py`:
- Around line 343-353: Add focused regression tests for the tenant-model
resolution branch in the parser, covering successful normalization to `@mineru`,
`@paddleocr`, and `@somark`. Also cover missing provider or instance records and
cross-tenant model references, asserting these cases do not fall through into
Vision parsing and preserve the expected rejection behavior.
- Around line 343-353: Add logging around the tenant-model resolution block in
the parser flow: record successful normalization with non-sensitive identifiers,
and emit warning or error logs when the tenant model, provider, or instance
lookup/configuration is invalid before the parser selection rejects it. Use the
module’s existing logger and ensure credentials or other sensitive configuration
values are never logged.
- Around line 346-350: Update the raw_parse_method handling in the parser flow
to recognize built-in parser literals such as deepdoc, mineru, paddleocr, and
somark before calling TenantModelService.get_by_id. Short-circuit those known
values so they do not trigger tenant-model, provider, or instance database
lookups, while preserving the existing resolver behavior for non-built-in names.
🪄 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 Plus
Run ID: 312a0cd5-c741-498a-9baa-a49e03090191
📒 Files selected for processing (1)
rag/flow/parser/parser.py
| # If raw_parse_method is a tenant_model ID, resolve it to | ||
| # model_name@instance_name@provider_name so the provider-specific | ||
| # branches below can match the per-provider suffix. | ||
| if isinstance(raw_parse_method, str) and raw_parse_method: | ||
| exist, model_obj = TenantModelService.get_by_id(raw_parse_method) | ||
| if exist: | ||
| provider_ok, provider_obj = TenantModelProviderService.get_by_id(model_obj.provider_id) | ||
| instance_ok, instance_obj = TenantModelInstanceService.get_by_id(model_obj.instance_id) | ||
| if provider_ok and instance_ok: | ||
| raw_parse_method = f"{model_obj.model_name}@{instance_obj.instance_name}@{provider_obj.provider_name}" | ||
|
|
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Scope and validate tenant parser models before normalization.
These lookups use global get_by_id, so they do not verify that the model/provider/instance belongs to self._canvas._tenant_id or that the instance belongs to the model’s provider. If provider or instance resolution fails, the ID remains unchanged and later falls through to the Vision parser instead of failing clearly.
Use the tenant-scoped provider lookup, validate the instance relationship, and raise a configuration error on partial resolution.
Proposed validation
+ tenant_id = self._canvas._tenant_id
if isinstance(raw_parse_method, str) and raw_parse_method:
exist, model_obj = TenantModelService.get_by_id(raw_parse_method)
if exist:
- provider_ok, provider_obj = TenantModelProviderService.get_by_id(model_obj.provider_id)
+ provider_ok, provider_obj = TenantModelProviderService.get_by_tenant_id_and_provider_id(
+ tenant_id, model_obj.provider_id
+ )
instance_ok, instance_obj = TenantModelInstanceService.get_by_id(model_obj.instance_id)
- if provider_ok and instance_ok:
- raw_parse_method = f"{model_obj.model_name}@{instance_obj.instance_name}@{provider_obj.provider_name}"
+ if not provider_ok or not instance_ok or instance_obj.provider_id != model_obj.provider_id:
+ raise RuntimeError("Invalid tenant PDF parser model configuration")
+ raw_parse_method = f"{model_obj.model_name}@{instance_obj.instance_name}@{provider_obj.provider_name}"🤖 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 `@rag/flow/parser/parser.py` around lines 343 - 353, Update the tenant-model
normalization block around TenantModelService.get_by_id to use tenant-scoped
lookups for the model and provider, and validate that the resolved instance
belongs to the model’s provider and self._canvas._tenant_id. If model, provider,
or instance resolution is partial or invalid, raise the established
configuration error instead of leaving raw_parse_method unchanged; only
normalize to the provider-qualified name after all validations pass.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17355 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wangq8
left a comment
There was a problem hiding this comment.
Thanks for this fix! The change looks clean and addresses a real gap — when parse_method is passed as a tenant_model ID (UUID) from the new Tenant LLM Provider UI, it was silently falling through all parser branches without matching.
What this does well:
- Minimal, focused change (14 lines, single file)
- Properly resolves tenant_model ID →
model_name@instance_name@provider_nameformat that the existing@somark/@mineru/@paddleocrsuffix checks expect - Guards each lookup result (
exist,provider_ok,instance_ok) before constructing the resolved string - No change to existing behavior when
raw_parse_methodis already a proper parser name
One small suggestion (non-blocking):
If the provider or instance lookup fails (e.g. data inconsistency), it currently fails silently — raw_parse_method stays as the raw UUID and falls through all parser branches. Consider adding a logging.warning(...) in the fall-through case to help with debugging.
Verified:
- All three service classes (
TenantModelService,TenantModelProviderService,TenantModelInstanceService) exist and inheritget_by_idfromCommonService - Model fields (
model_name,instance_name,provider_name) match the constructed format - No circular import risk — these are leaf DB service imports, consistent with existing patterns in this file
LGTM 👍
Summary
As title, recognize parse_method provider.