Skip to content

fix: derive Pydantic camelCase aliases via to_camel generator#1955

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

fix: derive Pydantic camelCase aliases via to_camel generator#1955
vdusek wants to merge 2 commits into
masterfrom
refactor/pydantic-camelcase-alias-generator

Conversation

@vdusek
Copy link
Copy Markdown
Collaborator

@vdusek vdusek commented Jun 8, 2026

Sets alias_generator=to_camel in each Pydantic model's ConfigDict so snake_case fields (de)serialize to camelCase keys automatically, instead of spelling out every Field(alias=...). Applied inline per model (no shared base class).

Explicit Field(alias=...) is kept only where to_camel yields the wrong key: the *Millis durations and crawlerLastStartTimestamp in StatisticsState, ProcessedRequest.idrequestId, EventMigratingData.time_remainingtimeRemainingSecs, and SitemapRequestLoaderState.completedsitemapCompleted.

A few fields were previously serialized with snake_case keys; they now use camelCase like everything else: the three AdaptivePlaywrightCrawlerStatisticState counters, EventCrawlerStatusData.crawler_idcrawlerId, and CrawleeRequestData.session_idsessionId. Old persisted snake_case data still loads via validate_by_name.

Skipped: Configuration (env-var AliasChoices), RequestQueueState (snake_case form), and UserData (arbitrary user keys).

Closes #1954

Replace manual per-field `Field(alias=...)` with `alias_generator=to_camel` in each model's
`ConfigDict`, keeping explicit aliases only where `to_camel` would produce a different key. The
serialized wire format is unchanged.
@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
@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 92.99%. Comparing base (66b4b5b) to head (b72f93e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1955      +/-   ##
==========================================
+ Coverage   92.98%   92.99%   +0.01%     
==========================================
  Files         167      167              
  Lines       11712    11723      +11     
==========================================
+ Hits        10890    10902      +12     
+ Misses        822      821       -1     
Flag Coverage Δ
unit 92.99% <100.00%> (+0.01%) ⬆️

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.

validate_by_name=True, validate_by_alias=True, alias_generator=to_camel, ser_json_inf_nan='constants'
)

# These fields are serialized with snake_case keys, so they keep explicit aliases that override the
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pijukatel the snake_case alias is a mistake, right?

@vdusek vdusek changed the title refactor: derive Pydantic camelCase aliases via to_camel generator fix: derive Pydantic camelCase aliases via to_camel generator Jun 8, 2026
@vdusek vdusek marked this pull request as ready for review June 8, 2026 13:20
@vdusek vdusek requested a review from Pijukatel June 8, 2026 13:21
@vdusek
Copy link
Copy Markdown
Collaborator Author

vdusek commented Jun 8, 2026

Well, there might be some compatibility issues; maybe we should resolve this as part of v2.0

@vdusek vdusek marked this pull request as draft June 8, 2026 13:39
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.

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

2 participants