fix: derive Pydantic camelCase aliases via to_camel generator#1955
Draft
vdusek wants to merge 2 commits into
Draft
fix: derive Pydantic camelCase aliases via to_camel generator#1955vdusek wants to merge 2 commits into
vdusek wants to merge 2 commits into
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
vdusek
commented
Jun 8, 2026
| 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 |
Collaborator
Author
There was a problem hiding this comment.
@Pijukatel the snake_case alias is a mistake, right?
…tus, and session_id
Collaborator
Author
|
Well, there might be some compatibility issues; maybe we should resolve this as part of v2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sets
alias_generator=to_camelin each Pydantic model'sConfigDictso snake_case fields (de)serialize to camelCase keys automatically, instead of spelling out everyField(alias=...). Applied inline per model (no shared base class).Explicit
Field(alias=...)is kept only whereto_camelyields the wrong key: the*Millisdurations andcrawlerLastStartTimestampinStatisticsState,ProcessedRequest.id→requestId,EventMigratingData.time_remaining→timeRemainingSecs, andSitemapRequestLoaderState.completed→sitemapCompleted.A few fields were previously serialized with snake_case keys; they now use camelCase like everything else: the three
AdaptivePlaywrightCrawlerStatisticStatecounters,EventCrawlerStatusData.crawler_id→crawlerId, andCrawleeRequestData.session_id→sessionId. Old persisted snake_case data still loads viavalidate_by_name.Skipped:
Configuration(env-varAliasChoices),RequestQueueState(snake_case form), andUserData(arbitrary user keys).Closes #1954