Skip to content

refactor: Use Pydantic models instead of custom dict representations#650

Draft
vdusek wants to merge 2 commits intomasterfrom
refactor/pydantic-request-models
Draft

refactor: Use Pydantic models instead of custom dict representations#650
vdusek wants to merge 2 commits intomasterfrom
refactor/pydantic-request-models

Conversation

@vdusek
Copy link
Contributor

@vdusek vdusek commented Feb 25, 2026

Summary

  • Replace hand-written _representations.py helper functions with Pydantic request models (CreateActorRequest, UpdateActorRequest, ScheduleCreate, WebhookCreate, etc.) for constructing API payloads
  • Simplify _update() / _create() in ResourceClient to accept **kwargs and use a new _clean_json_payload() method instead of the removed filter_none_values() utility
  • Remove unused enum_to_value() from _utils.py — Pydantic serialization handles enum conversion

Test plan

  • Verify existing unit tests pass
  • Verify integration tests pass against the Apify API
  • Confirm no regressions in Actor, Task, Schedule, Webhook, and Version CRUD operations

🤖 Generated with Claude Code

- Replace inline dicts in resource clients with Pydantic request models
  for type-safe request construction
- Move payload cleanup (None filtering) into base class as
  _clean_json_payload, replacing filter_none_values utility
- Simplify _create/_update signatures to accept **kwargs
- Add proper type conversions for list[dict] → list[Model], str → AnyUrl,
  dict → TaskInput
- Remove _representations.py (orphaned after Pydantic model migration)
- Remove enum_to_value utility (redundant with StrEnum)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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 Feb 25, 2026
@vdusek vdusek self-assigned this Feb 25, 2026
@github-actions github-actions bot added this to the 135th sprint - Tooling team milestone Feb 25, 2026
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Feb 25, 2026
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 57.41935% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.87%. Comparing base (230bb64) to head (1b03bbc).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/apify_client/_resource_clients/webhook.py 20.00% 8 Missing ⚠️
...ify_client/_resource_clients/webhook_collection.py 20.00% 8 Missing ⚠️
src/apify_client/_resource_clients/actor.py 42.85% 4 Missing ⚠️
...apify_client/_resource_clients/actor_collection.py 33.33% 4 Missing ⚠️
...rc/apify_client/_resource_clients/actor_version.py 42.85% 4 Missing ⚠️
...ient/_resource_clients/actor_version_collection.py 33.33% 4 Missing ⚠️
src/apify_client/_resource_clients/schedule.py 33.33% 4 Missing ⚠️
...fy_client/_resource_clients/schedule_collection.py 20.00% 4 Missing ⚠️
src/apify_client/_resource_clients/task.py 20.00% 4 Missing ⚠️
.../apify_client/_resource_clients/task_collection.py 33.33% 4 Missing ⚠️
... and 9 more

❗ There is a different number of reports uploaded between BASE (230bb64) and HEAD (1b03bbc). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (230bb64) HEAD (1b03bbc)
integration 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #650       +/-   ##
===========================================
- Coverage   96.62%   76.87%   -19.76%     
===========================================
  Files          45       45               
  Lines        4271     4320       +49     
===========================================
- Hits         4127     3321      -806     
- Misses        144      999      +855     
Flag Coverage Δ
integration ?
unit 76.87% <57.41%> (+1.27%) ⬆️

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.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vdusek vdusek changed the title refactor!: Use Pydantic request models and simplify base client internals refactor: Use Pydantic request models and simplify base client internals Feb 25, 2026
@vdusek vdusek changed the title refactor: Use Pydantic request models and simplify base client internals refactor: Use Pydantic models instead of custom dict representations Feb 25, 2026
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