Skip to content

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

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Lower Boundary
(Limit %)
sync-v2 (up to 20000 blocks)Latency
minutes (m)
📈 plot
🚷 threshold
🚨 alert (🔔)
1.36 m
(-20.56%)Baseline: 1.72 m
1.54 m
(113.29%)

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
🚨 view alert (🔔)
1.36 m
(-20.56%)Baseline: 1.72 m
1.54 m
(113.29%)

2.06 m
(66.20%)
🐰 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
db_basic_settings = db_settings.copy(deep=True, exclude={'features'})
new_basic_settings = new_settings.copy(deep=True, exclude={'features'})
db_settings: FeatureActivationSettings = FeatureActivationSettings.model_validate_json(db_settings_bytes)
db_basic_settings = db_settings.model_copy(deep=True, update={'features': {}})
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather use exclude instead of update.

Copy link
Member Author

@msbrogli msbrogli Jan 23, 2026

Choose a reason for hiding this comment

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

It seems exclude is not available in Pydantic v2. I guess it is ok to simply replace it by an empty dict.


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 95.96774% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.26%. Comparing base (a010288) to head (84527e6).

Files with missing lines Patch % Lines
hathor/consensus/poa/poa_signer.py 78.26% 2 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   86.33%   86.26%   -0.07%     
==========================================
  Files         437      437              
  Lines       33645    33610      -35     
  Branches     5258     5259       +1     
==========================================
- Hits        29047    28994      -53     
- Misses       3594     3606      +12     
- Partials     1004     1010       +6     

☔ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress (Done)

Development

Successfully merging this pull request may close these issues.

2 participants