Fokko commented on code in PR #6525:
URL: https://github.com/apache/iceberg/pull/6525#discussion_r1064725064
##########
python/pyiceberg/utils/iceberg_base_model.py:
##########
@@ -60,3 +63,39 @@ def json(self, exclude_none: bool = True, exclude:
Optional[Set[str]] = None, by
return super().json(
exclude_none=exclude_none,
exclude=self._exclude_private_properties(exclude), by_alias=by_alias, **kwargs
)
+
+
+class PydanticStruct(IcebergBaseModel):
+ class Config:
+ frozen = False
+
+ def __setitem__(self, pos: int, value: Any) -> None:
+ positions = list(self.__fields__.values())
+ self.__setattr__(positions[pos].name, value)
+
+ def __getitem__(self, pos: int) -> Any:
+ positions = list(self.__fields__.values())
+ return self.__getattribute__(positions[pos].name)
+
+
+class Record(PydanticStruct):
Review Comment:
Ah, I remember. If you use Pydantic classes with downstream fields, Pydantic
expects it to be a pydantic class as well:
```
ImportError while loading conftest
'/Users/fokkodriesprong/Desktop/iceberg/python/tests/conftest.py'.
tests/conftest.py:48: in <module>
from tests.catalog.test_base import InMemoryCatalog
tests/catalog/test_base.py:28: in <module>
from pyiceberg.catalog import (
pyiceberg/catalog/__init__.py:36: in <module>
from pyiceberg.manifest import ManifestFile
pyiceberg/manifest.py:162: in <module>
class DataFile(PydanticStruct):
pydantic/main.py:198: in pydantic.main.ModelMetaclass.__new__
???
pydantic/fields.py:506: in pydantic.fields.ModelField.infer
???
pydantic/fields.py:436: in pydantic.fields.ModelField.__init__
???
pydantic/fields.py:557: in pydantic.fields.ModelField.prepare
???
pydantic/fields.py:831: in pydantic.fields.ModelField.populate_validators
???
pydantic/validators.py:765: in find_validators
???
E RuntimeError: no validator found for <class 'pyiceberg.typedef.Record'>,
see `arbitrary_types_allowed` in Config
make: *** [test] Error 4
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]