Skip to content

Commit 6f2b0d7

Browse files
committed
fix: Validate SetStatisticsUpdate correctly (fixes #2865)
Previously the pydantic @model_validator would fail because it assumed statistics was a model instance. In a "before"" validator that is not the case. Use an "after" validator instead, where we can use instantiated and validated fields.
1 parent b0a7878 commit 6f2b0d7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

pyiceberg/table/update/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from abc import ABC, abstractmethod
2222
from datetime import datetime
2323
from functools import singledispatch
24-
from typing import TYPE_CHECKING, Annotated, Any, Generic, Literal, TypeVar, cast
24+
from typing import TYPE_CHECKING, Annotated, Any, Generic, Literal, TypeVar, cast, Self
2525

2626
from pydantic import Field, field_validator, model_serializer, model_validator
2727

@@ -179,13 +179,9 @@ class SetStatisticsUpdate(IcebergBaseModel):
179179
description="snapshot-id is **DEPRECATED for REMOVAL** since it contains redundant information. Use `statistics.snapshot-id` field instead.",
180180
)
181181

182-
@model_validator(mode="before")
183-
def validate_snapshot_id(cls, data: dict[str, Any]) -> dict[str, Any]:
184-
stats = cast(StatisticsFile, data["statistics"])
185-
186-
data["snapshot_id"] = stats.snapshot_id
187-
188-
return data
182+
@model_validator(mode="after")
183+
def validate_snapshot_id(self) -> Self:
184+
return self.model_copy(update={"snapshot_id": self.statistics.snapshot_id})
189185

190186

191187
class RemoveStatisticsUpdate(IcebergBaseModel):

0 commit comments

Comments
 (0)