Skip to content

fix!: apply to_camel alias generator to all Pydantic models#950

Draft
vdusek wants to merge 2 commits into
masterfrom
refactor/pydantic-alias-generator
Draft

fix!: apply to_camel alias generator to all Pydantic models#950
vdusek wants to merge 2 commits into
masterfrom
refactor/pydantic-alias-generator

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Jun 8, 2026

Closes #949.

Warning

Breaking change (targets the v4 major). The wire keys produced by by-alias serialization change for some models. Reading data stays backwards compatible.

Every Pydantic model in the SDK now derives its JSON field aliases from the snake_case field names with Pydantic's alias_generator=to_camel, instead of declaring each alias by hand. The config (ConfigDict(populate_by_name=True, alias_generator=to_camel, ...)) is repeated per model rather than shared via a base class.

Scope

  • Applied to all 38 data/API models across _models.py, storage_clients/_apify/_models.py, events/_types.py, and request_loaders/_apify_request_list.py.
  • Configuration is the only model left untouched, because its fields map to APIFY_* / CRAWLEE_* environment variables via validation aliases. Applying to_camel there would break env-based configuration.

Breaking changes

Attribute names are unchanged (run.usage.actor_compute_units still works). Only by-alias serialization keys change, and only where they were not already camelCase:

  • ActorRunUsage / ActorRunUsageUsd: ACTOR_COMPUTE_UNITS, DATASET_READS, … → actorComputeUnits, datasetReads, …
  • RequestQueueHead: lockSecslockTime.

Backwards compatibility

Validation still accepts the previous keys, so existing API payloads and stored data keep parsing:

  • The usage models accept both the camelCase keys and the legacy all-caps keys (via AliasChoices).
  • RequestQueueHead accepts both lockTime and the legacy lockSecs.

Docs

Documented in the v4 upgrading guide (docs/04_upgrading/upgrading_to_v4.md).

@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Jun 8, 2026
@vdusek vdusek self-assigned this Jun 8, 2026
@github-actions github-actions Bot added this to the 142nd sprint - Tooling team milestone Jun 8, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Jun 8, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.02%. Comparing base (902a66d) to head (94bcef2).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #950      +/-   ##
==========================================
+ Coverage   86.88%   87.02%   +0.14%     
==========================================
  Files          48       48              
  Lines        2943     2960      +17     
==========================================
+ Hits         2557     2576      +19     
+ Misses        386      384       -2     
Flag Coverage Δ
e2e 38.04% <97.39%> (+0.28%) ⬆️
integration 59.25% <97.39%> (+0.16%) ⬆️
unit 75.84% <100.00%> (+0.20%) ⬆️

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

☔ 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.

BREAKING CHANGE: every Pydantic model except Configuration now derives its JSON
aliases from snake_case field names via to_camel, so by-alias serialization is
uniformly camelCase. ActorRunUsage/ActorRunUsageUsd keys change from
ACTOR_COMPUTE_UNITS-style to actorComputeUnits-style, and RequestQueueHead from
lockSecs to lockTime. The legacy keys are still accepted on input for backwards
compatibility. Attribute names are unchanged.
@vdusek vdusek changed the title refactor: derive Pydantic model aliases with to_camel fix!: apply to_camel alias generator to all Pydantic models Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Use alias_generator=to_camel on Pydantic models instead of manual per-field aliases

2 participants