X Tutup
Skip to content

feat: Accept Pydantic models as alternatives to dicts in resource client methods#663

Open
vdusek wants to merge 1 commit intomasterfrom
feat/union-dict-model-types
Open

feat: Accept Pydantic models as alternatives to dicts in resource client methods#663
vdusek wants to merge 1 commit intomasterfrom
feat/union-dict-model-types

Conversation

@vdusek
Copy link
Contributor

@vdusek vdusek commented Mar 6, 2026

Changes summary

  • Accept dict | PydanticModel union types in resource client methods that previously only accepted dict, enabling type-safe usage alongside plain dict input.
  • Dicts are validated through Pydantic internally, catching schema errors earlier than the API would.
  • Replace the dict-based encode_webhook_list_to_base64 utility with a structured WebhookRepresentationList model that handles validation and base64 encoding.
  • Add RequestInput and RequestDeleteInput models in _types.py for RQ operations, matching the actual API schema requirements.

Motivation

Improve typing on the input side of resource client methods. We don't want to accept only Pydantic models, which would require users to import additional classes. Instead, methods now accept both dict and the corresponding Pydantic model. This way, users don't have to import anything extra, but can optionally use the model types for type-safe usage and to discover the expected dict shape.

Next steps

Once we fully update the OpenAPI spec (apify/apify-docs#2286), we can remove the manually created models in _types.py and replace them with the generated ones.

Test plan

  • CI passes

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Mar 6, 2026
@vdusek vdusek self-assigned this Mar 6, 2026
@github-actions github-actions bot added this to the 135th sprint - Tooling team milestone Mar 6, 2026
@vdusek vdusek changed the title Accept Pydantic models as alternatives to dicts in resource client methods feat: accept Pydantic models as alternatives to dicts in resource client methods Mar 6, 2026
@danpoletaev danpoletaev force-pushed the feat/union-dict-model-types branch from ac60efe to a1715c9 Compare March 6, 2026 21:55
@B4nan B4nan force-pushed the feat/union-dict-model-types branch from a1715c9 to ac60efe Compare March 6, 2026 22:54
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Mar 7, 2026
@vdusek vdusek force-pushed the feat/union-dict-model-types branch from 322306d to e68c909 Compare March 9, 2026 13:50
@vdusek vdusek force-pushed the feat/union-dict-model-types branch from e68c909 to 0d584bc Compare March 9, 2026 15:03
@vdusek vdusek marked this pull request as ready for review March 9, 2026 15:03
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 89.28571% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.93%. Comparing base (723ec6e) to head (0d584bc).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/apify_client/_types.py 88.37% 5 Missing ⚠️
src/apify_client/_resource_clients/task.py 77.77% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #663      +/-   ##
==========================================
+ Coverage   94.83%   94.93%   +0.09%     
==========================================
  Files          45       45              
  Lines        4340     4401      +61     
==========================================
+ Hits         4116     4178      +62     
+ Misses        224      223       -1     
Flag Coverage Δ
integration 94.93% <89.28%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@vdusek vdusek changed the title feat: accept Pydantic models as alternatives to dicts in resource client methods feat: Accept Pydantic models as alternatives to dicts in resource client methods Mar 9, 2026
@vdusek vdusek requested review from Pijukatel and janbuchar March 9, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup