fix(salesforce): build query/search results via model_validate#163
Conversation
QueryRecordsResult and SearchRecordsResult declare their API fields with Field(alias=...) and populate_by_name=True. Constructing them by Python field name (total_size=, search_records=) is valid at runtime, but ty synthesizes __init__ from the alias only and rejects the field name, forcing scoped ty:ignore suppressions. Parse the raw API JSON with model_validate instead. The JSON already carries the aliases (totalSize, searchRecords) and the models' _set_success validator defaults success=True when absent, so behavior is unchanged. This removes both ty:ignore[unknown-argument] suppressions. Closes #161
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Pull request overview
This pull request updates the Salesforce provider’s query/search tool implementations to construct QueryRecordsResult and SearchRecordsResult via Pydantic model_validate(...) on the raw API JSON, aligning runtime behavior with ty’s alias-based __init__ modeling and removing the need for # ty: ignore[unknown-argument] suppressions.
Changes:
- Replace manual
QueryRecordsResult(...)construction withQueryRecordsResult.model_validate(response.json()). - Replace manual
SearchRecordsResult(...)construction withSearchRecordsResult.model_validate(response.json()). - Remove the two scoped
tysuppressions related to aliased fields (totalSize,searchRecords).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
QueryRecordsResultandSearchRecordsResultdeclare their API fields withField(alias=...)andpopulate_by_name=True. The tool code constructed them by Python field name (total_size=,search_records=) — valid at runtime, butty(0.0.56) synthesizes__init__from the alias only and rejects the field name, which had forced two scoped# ty: ignore[unknown-argument]suppressions.Fix
Parse the raw API JSON with
model_validateinstead of hand-mapping fields:The API JSON already carries the aliases (
totalSize,searchRecords), and each model's existing_set_successmodel_validatordefaultssuccess=Truewhen the key is absent — so behavior is unchanged. Bothty: ignoresuppressions are removed (including the pre-existing one at the former line 168, per the note on #161).Verification
uv run ty check src/apron_tools→ All checks passed! (no diagnostics, no suppressions).uv run pytest tests/providers/salesforce/→ 60 passed.uv run pre-commit run --all-files→ all hooks pass.model_validate: missingdone/totalSize/searchRecordsfall back to model defaults, and an explicitsuccessin the payload is respected (validator only defaults when absent).Closes #161