Skip to content

refactor: Upgrade to Pydantic v2#1566

Merged
msbrogli merged 1 commit intomasterfrom
refactor/pydantic-v2
Feb 12, 2026
Merged

refactor: Upgrade to Pydantic v2#1566
msbrogli merged 1 commit intomasterfrom
refactor/pydantic-v2

Conversation

@msbrogli
Copy link
Member

@msbrogli msbrogli commented Jan 21, 2026

Motivation

This PR upgrades the codebase from Pydantic v1 to Pydantic v2.

Acceptance Criteria

  • Update pydantic dependency from ~1.10.26 to ^2.0 in pyproject.toml
  • Migrate @validator decorators to @field_validator with mode='before'/mode='after' instead of pre=True
  • Migrate cross-field validators to @model_validator(mode='after') pattern, replacing values dict access with direct model attribute access
  • Replace Extra.ignore and other class-level config with model_config = ConfigDict(...)
  • Replace .dict() calls with .model_dump()
  • Update discriminated unions to use Discriminator() and Tag() from pydantic
  • Remove deprecated allow_reuse=True and each_item=True parameters (handled differently in v2)
  • Add @classmethod decorator to field validators as required by v2
  • Add Hex[bytes] type annotation for automatic hex string parsing

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@msbrogli msbrogli requested a review from jansegre as a code owner January 21, 2026 19:21
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from 859455c to 47951bb Compare January 21, 2026 19:58
@msbrogli msbrogli self-assigned this Jan 21, 2026
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from 47951bb to 03c9489 Compare January 22, 2026 17:36
@github-actions
Copy link

github-actions bot commented Jan 22, 2026

🐰 Bencher Report

Branchrefactor/pydantic-v2
Testbedubuntu-22.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
minutes (m)
(Result Δ%)
Lower Boundary
minutes (m)
(Limit %)
Upper Boundary
minutes (m)
(Limit %)
sync-v2 (up to 20000 blocks)📈 view plot
🚷 view threshold
1.68 m
(-1.91%)Baseline: 1.71 m
1.54 m
(91.75%)
2.06 m
(81.74%)
🐰 View full continuous benchmarking report in Bencher

@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from 517d775 to 7250d52 Compare January 22, 2026 17:49

class SideDagArgs(RunNodeArgs):
poa_signer_file: str | None
poa_signer_file: str | None = None
Copy link
Member Author

Choose a reason for hiding this comment

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

Can it really be None?

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 96.34146% with 9 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@8cd820c). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
hathor/consensus/poa/poa_signer.py 80.95% 1 Missing and 3 partials ⚠️
hathor/utils/named_tuple.py 75.00% 2 Missing and 1 partial ⚠️
hathor/utils/pydantic.py 90.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1566   +/-   ##
=========================================
  Coverage          ?   85.69%           
=========================================
  Files             ?      441           
  Lines             ?    33793           
  Branches          ?     5286           
=========================================
  Hits              ?    28959           
  Misses            ?     3817           
  Partials          ?     1017           
Flag Coverage Δ
test-lib 85.69% <96.34%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from 107d6c4 to d0ac1fe Compare January 22, 2026 18:24
Comment on lines +133 to +134
token_name: Optional[str] = None
token_symbol: Optional[str] = None
Copy link
Member Author

Choose a reason for hiding this comment

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

Pydantic v2 requires default value to ignore missing parameters. Should these None be included?

@msbrogli msbrogli moved this from Todo to In Progress (Done) in Hathor Network Jan 22, 2026
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from d0ac1fe to 84527e6 Compare January 23, 2026 16:40
@msbrogli msbrogli moved this from In Progress (Done) to In Review (WIP) in Hathor Network Jan 27, 2026
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch 2 times, most recently from eaa0320 to cc58057 Compare January 27, 2026 23:56
jansegre
jansegre previously approved these changes Feb 9, 2026
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch 3 times, most recently from 8851d00 to f27149c Compare February 10, 2026 16:22
@msbrogli msbrogli moved this from In Review (WIP) to In Review (Done) in Hathor Network Feb 10, 2026
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from f27149c to 42d0e73 Compare February 10, 2026 17:27
glevco
glevco previously approved these changes Feb 10, 2026
jansegre
jansegre previously approved these changes Feb 10, 2026
@github-project-automation github-project-automation bot moved this from In Review (Done) to In Review (WIP) in Hathor Network Feb 10, 2026
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from 42d0e73 to b88a3e9 Compare February 10, 2026 17:43
@msbrogli msbrogli moved this from In Review (WIP) to In Review (Done) in Hathor Network Feb 10, 2026
@msbrogli msbrogli dismissed stale reviews from jansegre and glevco via d31d010 February 10, 2026 17:49
@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch 3 times, most recently from 8e4ffb1 to caca25d Compare February 12, 2026 19:15
glevco
glevco previously approved these changes Feb 12, 2026
@msbrogli msbrogli dismissed glevco’s stale review February 12, 2026 20:03

The merge-base changed after approval.

@msbrogli msbrogli force-pushed the refactor/pydantic-v2 branch from caca25d to 8ea0e10 Compare February 12, 2026 20:05
@msbrogli msbrogli merged commit 8ea0e10 into master Feb 12, 2026
28 of 31 checks passed
@msbrogli msbrogli deleted the refactor/pydantic-v2 branch February 12, 2026 20:06
@github-project-automation github-project-automation bot moved this from In Review (Done) to Waiting to be deployed in Hathor Network Feb 12, 2026
@jansegre jansegre mentioned this pull request Mar 5, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting to be deployed

Development

Successfully merging this pull request may close these issues.

3 participants