Skip to content

refactor: derive Pydantic model field aliases with to_camel#950

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

refactor: derive Pydantic model field aliases with to_camel#950
vdusek wants to merge 2 commits into
masterfrom
refactor/pydantic-alias-generator

Conversation

@vdusek

@vdusek vdusek commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Closes #949.

Replaces hand-written per-field Field(alias=...) declarations with Pydantic's alias_generator=to_camel, so each model derives its camelCase JSON aliases from its snake_case field names.

Following the existing convention in this repo, the config (ConfigDict(populate_by_name=True, alias_generator=to_camel, ...)) is repeated per model rather than introduced through a shared base class.

Scope

  • _charging.py — the pricing-info and charge-event models.
  • events/_types.pySystemInfoEventData and the event wrapper models.
  • request_loaders/_apify_request_list.py — the request-input models.
  • storage_clients/_apify/_models.pyApifyKeyValueStoreMetadata, RequestQueueHead, CachedRequest, ApifyRequestQueueMetadata.

No breaking change

The generated aliases match the aliases that were declared by hand, so validation and serialization keep the same wire keys. Attribute names are unchanged (run.usage.actor_compute_units and friends still work).

The one field whose name differs from its wire key is RequestQueueHead.lock_time. The API sends lockSecs, while to_camel would derive lockTime. It keeps serialization_alias='lockSecs' so it still emits lockSecs, and it now validates from both lockSecs and lockTime via AliasChoices. That change is additive. Nothing that parsed before stops parsing.

Configuration is intentionally left untouched. Its fields bind to APIFY_* / CRAWLEE_* environment variables through validation aliases, so applying to_camel there would break env-based configuration.

@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

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.14%. Comparing base (03f97a3) to head (3f2ff93).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #950      +/-   ##
==========================================
+ Coverage   87.08%   87.14%   +0.06%     
==========================================
  Files          48       48              
  Lines        2973     2996      +23     
==========================================
+ Hits         2589     2611      +22     
- Misses        384      385       +1     
Flag Coverage Δ
e2e ?
integration 58.67% <92.42%> (+0.28%) ⬆️
unit 75.60% <100.00%> (+0.12%) ⬆️

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.

@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
@vdusek

vdusek commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Finish this after merging #719

@vdusek vdusek force-pushed the refactor/pydantic-alias-generator branch 4 times, most recently from d54ef06 to db193c5 Compare June 9, 2026 12:07
@vdusek vdusek changed the title fix!: apply to_camel alias generator to all Pydantic models refactor: derive Pydantic model field aliases with to_camel Jun 9, 2026
vdusek added a commit that referenced this pull request Jun 9, 2026
Split out from #950 (the other half is the `to_camel` alias refactor).

Adds concise class and field docstrings to all `@docs_group`-decorated
models that were missing them:

- `events/_types.py` — `SystemInfoEventData` (8 resource-usage metric
fields) and the 8 event wrappers (`name` / `data`).
- `_charging.py` — the pricing-info models, plus module-level constant
docstrings and a few inline comments converted to docstrings.

Also inlines the private `_RelaxedPricingMetadata` mixin into the four
pricing subclasses so each documents its own relaxed fields. This is
behavior-preserving (field order, aliases, and requiredness are
unchanged).

This PR keeps the manual field aliases and branches from `master`
independently of #950. Once #950 merges, this branch will need a rebase
to resolve the overlapping changes in `_charging.py` /
`events/_types.py`.
@vdusek vdusek force-pushed the refactor/pydantic-alias-generator branch from db193c5 to 7d3997c Compare June 9, 2026 14:37
@vdusek vdusek marked this pull request as ready for review June 9, 2026 14:40
@vdusek vdusek requested a review from Pijukatel June 9, 2026 14:43
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