Skip to content

feat: unify provider id or name routing - #16336

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:b096
Jun 25, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:b096

Conversation

@buua436

@buua436 buua436 commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Unifies provider and instance-related provider API routes to accept either an ID or a name.

Type of change

  • Feature (non-breaking change which adds functionality)

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63e5316e-65d6-43bb-b6d1-565a4e113aa9

📥 Commits

Reviewing files that changed from the base of the PR and between c9d1208 and f18f4a4.

📒 Files selected for processing (3)
  • api/apps/restful_apis/provider_api.py
  • api/apps/services/provider_api_service.py
  • api/db/services/tenant_model_provider_service.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • api/db/services/tenant_model_provider_service.py
  • api/apps/services/provider_api_service.py
  • api/apps/restful_apis/provider_api.py

📝 Walkthrough

Walkthrough

Provider and instance endpoints now accept ID-or-name path parameters. Service methods resolve providers and instances by ID first, then name, and tenant provider lookup gained a provider-ID helper.

Changes

Provider and instance identifier resolution

Layer / File(s) Summary
Tenant provider ID lookup
api/db/services/tenant_model_provider_service.py
Adds get_by_tenant_id_and_provider_id inside DB.connection_context to fetch a tenant model provider by tenant ID and provider ID.
Provider-level service resolution
api/apps/services/provider_api_service.py
Updates provider delete, show, model listing, instance listing, create, and API-key verification flows to accept provider_id_or_name and resolve providers by ID first, then by name.
Instance and model service resolution
api/apps/services/provider_api_service.py
Updates instance show, drop, list, update, add, status, and chat flows to accept provider_id_or_name and instance_id_or_name, resolve instance ownership, and update error messages.
Provider route parameter rename
api/apps/restful_apis/provider_api.py
Renames provider path parameters to provider_id_or_name, updates Swagger text, and forwards the renamed values to the service calls.
Instance route parameter rename
api/apps/restful_apis/provider_api.py
Renames provider and instance path parameters to provider_id_or_name and instance_id_or_name, updates Swagger text, and forwards the renamed values to the service calls.

Sequence Diagram(s)

sequenceDiagram
  participant ChatRoute as "provider_api.chat_to_model"
  participant ChatService as "provider_api_service.chat_to_model"
  participant ProviderLookup as "TenantModelProviderService.get_by_tenant_id_and_provider_id"
  participant TenantModelProvider
  ChatRoute->>ChatService: provider_id_or_name, instance_id_or_name
  ChatService->>ProviderLookup: lookup tenant_id and provider_id
  ProviderLookup->>TenantModelProvider: get_or_none(tenant_id, id)
  TenantModelProvider-->>ProviderLookup: provider row or null
  ProviderLookup-->>ChatService: resolved provider
  ChatService->>ChatService: resolve instance_id_or_name and build composite_name
  ChatService-->>ChatRoute: chat response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • infiniflow/ragflow#16028: Overlaps with the update_instance_models path and the same provider/instance identifier wiring in provider_api_service.
  • infiniflow/ragflow#16131: Touches the same provider/instance API surface and nearby endpoint wiring for provider instance creation.

Poem

I hopped through names and IDs at night,
Then found each provider by rabbit sight.
Instances twinkled, models chimed,
Chat streams flowed right on time.
🐇 Thump! The burrow path aligned.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main routing change.
Description check ✅ Passed The description includes the required problem statement and type-of-change section, and it is sufficiently specific.
Docstring Coverage ✅ Passed Docstring coverage is 82.35% which is sufficient. The required threshold is 80.00%.
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.

✏️ 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.

❤️ Share

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

@buua436 buua436 added the ci Continue Integration label Jun 25, 2026
@buua436
buua436 requested a review from Lynn-Inf June 25, 2026 03:09
@buua436
buua436 marked this pull request as ready for review June 25, 2026 03:09
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 25, 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/apps/restful_apis/provider_api.py (1)

515-566: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject wrong body types before dispatching to the service layer.

These handlers only check that keys exist. If a client sends "instances": "abc" or "model_name": "gpt-4", "model_type": "chat", the downstream service code will iterate characters and attempt bogus deletes/updates instead of returning a 400. Please switch these request bodies to Pydantic models so the new ID-or-name routes validate shape and type up front. As per coding guidelines, api/apps/restful_apis/**/*.py: Use Pydantic request validation in RESTful APIs.

Also applies to: 633-685

🤖 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/restful_apis/provider_api.py` around lines 515 - 566, The request
handlers are only checking for required keys and can accept wrong body types, so
invalid payloads slip through to the service layer. Update
drop_provider_instances and the other ID-or-name handler in provider_api to use
Pydantic request models instead of raw request.get_json() dict checks, so fields
like instances/model_name/model_type are validated for shape and type before
calling provider_api_service. Keep the existing error handling, but let the
model validation return 400s for malformed bodies.

Source: Coding guidelines

🧹 Nitpick comments (1)
api/apps/services/provider_api_service.py (1)

190-194: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Extract and log the ID-or-name resolution path once.

This PR copies the same provider/instance resolution branch across most service methods, but none of the new paths record whether resolution hit by ID, fell back to name, or failed. Centralizing that logic would reduce drift and give you one place to add the logging this new flow needs. As per coding guidelines, **/*.py: Add logging for new flows.

Also applies to: 217-220, 262-266, 313-317, 364-368, 409-423, 572-586, 608-629, 701-726, 735-748, 773-786, 835-850, 904-918

🤖 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/provider_api_service.py` around lines 190 - 194, Centralize
the repeated provider_id_or_name resolution in ProviderApiService so the
ID-or-name path is extracted once and logged consistently. Move the shared
lookup logic used around provider_obj/provider_name/fac_list into a single
helper in ProviderApiService, and have each caller use it so you can log whether
get_by_id resolved by ID, fell back to the raw name, or failed. Add logging in
that helper for the new flow and update the affected service methods to call it
instead of duplicating the branch.

Source: Coding guidelines

🤖 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/provider_api_service.py`:
- Around line 173-179: The provider cleanup flow in provider_api_service is
returning early in the instance-removal path, which prevents deleting the
TenantModelProviderService record when a provider has no remaining instances.
Update the logic around get_all_by_provider_id in the delete-provider flow so it
still calls TenantModelProviderService.delete_by_tenant_id_and_provider_name
even when instance_objs is empty, while only skipping
delete_models_by_instance_ids and delete_instances_by_provider_ids when there
are no instance IDs to remove.

---

Outside diff comments:
In `@api/apps/restful_apis/provider_api.py`:
- Around line 515-566: The request handlers are only checking for required keys
and can accept wrong body types, so invalid payloads slip through to the service
layer. Update drop_provider_instances and the other ID-or-name handler in
provider_api to use Pydantic request models instead of raw request.get_json()
dict checks, so fields like instances/model_name/model_type are validated for
shape and type before calling provider_api_service. Keep the existing error
handling, but let the model validation return 400s for malformed bodies.

---

Nitpick comments:
In `@api/apps/services/provider_api_service.py`:
- Around line 190-194: Centralize the repeated provider_id_or_name resolution in
ProviderApiService so the ID-or-name path is extracted once and logged
consistently. Move the shared lookup logic used around
provider_obj/provider_name/fac_list into a single helper in ProviderApiService,
and have each caller use it so you can log whether get_by_id resolved by ID,
fell back to the raw name, or failed. Add logging in that helper for the new
flow and update the affected service methods to call it instead of duplicating
the branch.
🪄 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: d4a65f4d-489e-4342-8ef1-cd1bd3f52c72

📥 Commits

Reviewing files that changed from the base of the PR and between 06d45c5 and c9d1208.

📒 Files selected for processing (3)
  • api/apps/restful_apis/provider_api.py
  • api/apps/services/provider_api_service.py
  • api/db/services/tenant_model_provider_service.py

@Lynn-Inf Lynn-Inf 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.

LGTM

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (06d45c5) to head (f18f4a4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16336   +/-   ##
=======================================
  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.

@wangq8
wangq8 merged commit 479a9a7 into infiniflow:main Jun 25, 2026
3 checks passed
@wangq8 wangq8 mentioned this pull request Jun 25, 2026
1 task done
This was referenced Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants