Skip to content

refactor: unify alias vs validation_alias usage in Pydantic models#1022

Merged
vdusek merged 3 commits into
masterfrom
worktree-pydantic-alias-usage
Jul 3, 2026
Merged

refactor: unify alias vs validation_alias usage in Pydantic models#1022
vdusek merged 3 commits into
masterfrom
worktree-pydantic-alias-usage

Conversation

@vdusek

@vdusek vdusek commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Pydantic's alias sets both the validation and the serialization name, while validation_alias affects only validation. Configuration mixed the two, so model_dump(by_alias=True) was incoherent — e.g. is_at_home dumped as apify_is_at_home but started_at dumped as started_at.

This makes serialization consistent: model_dump(by_alias=True) now emits camelCase names derived from the Python field name across all Pydantic models.

  • _configuration.py — each field is validated from its environment variable(s) via validation_alias (a plain string, or AliasChoices(...) for legacy names). Serialization is handled by a model-level alias_generator=AliasGenerator(serialization_alias=to_camel), so e.g. is_at_homeisAtHome, actor_idactorId, max_paid_dataset_itemsmaxPaidDatasetItems. This also covers the fields inherited from Crawlee's base Configuration.
  • API / event / data models (_charging.py, events/_types.py, storage_clients/_apify/_models.py, request_loaders/_apify_request_list.py) already serialize camelCase via alias_generator=to_camel; RequestQueueHead.lock_time keeps its explicit serialization_alias='lockSecs' where the wire name differs from the field-derived one. Left as-is.
  • CLAUDE.md — documents the convention.

One inherited Crawlee field, internal_timeout, is defined with alias='crawlee_internal_timeout' (not validation_alias), which pins its serialization so the generator can't override it. It's outside this repo's control.

Closes #807

@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Jul 3, 2026
@vdusek vdusek self-assigned this Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.69%. Comparing base (4ead0c6) to head (1fb0cbc).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1022      +/-   ##
==========================================
- Coverage   91.72%   91.69%   -0.03%     
==========================================
  Files          50       50              
  Lines        3213     3215       +2     
==========================================
+ Hits         2947     2948       +1     
- Misses        266      267       +1     
Flag Coverage Δ
e2e 35.64% <100.00%> (+0.04%) ⬆️
integration 57.38% <100.00%> (+0.02%) ⬆️
unit 83.01% <100.00%> (-0.03%) ⬇️

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 requested a review from Pijukatel July 3, 2026 10:55
@vdusek vdusek marked this pull request as ready for review July 3, 2026 10:55
@vdusek vdusek merged commit a2ba2ad into master Jul 3, 2026
31 checks passed
@vdusek vdusek deleted the worktree-pydantic-alias-usage branch July 3, 2026 13:36
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit and unify usage of alias vs validation_alias in Pydantic models

3 participants