migrate remaining __fields__ to model_fields
This commit is contained in:
parent
ce06bf0114
commit
67c81489cf
@ -188,7 +188,7 @@ def _compile_client_storage_recursive(
|
||||
cookies = {}
|
||||
local_storage = {}
|
||||
state_name = state.get_full_name()
|
||||
for name, field in state.__fields__.items():
|
||||
for name, field in state.model_fields.items():
|
||||
if name in state.inherited_vars:
|
||||
# only include vars defined in this state
|
||||
continue
|
||||
|
@ -70,7 +70,7 @@ class ChakraProvider(ChakraComponent):
|
||||
|
||||
def _get_imports(self) -> imports.ImportDict:
|
||||
_imports = super()._get_imports()
|
||||
_imports.setdefault(self.__fields__["library"].default, []).append(
|
||||
_imports.setdefault(self.model_fields["library"].default, []).append(
|
||||
imports.ImportVar(tag="extendTheme", is_default=False),
|
||||
)
|
||||
_imports.setdefault("/utils/theme.js", []).append(
|
||||
|
@ -101,7 +101,7 @@ class RadixThemesComponent(Component):
|
||||
"""
|
||||
component = super().create(*children, **props)
|
||||
if component.library is None:
|
||||
component.library = RadixThemesComponent.__fields__["library"].default
|
||||
component.library = RadixThemesComponent.model_fields["library"].default
|
||||
component.alias = "RadixThemes" + (
|
||||
component.tag or component.__class__.__name__
|
||||
)
|
||||
|
@ -61,12 +61,12 @@ class Model(Base, sqlmodel.SQLModel):
|
||||
"""Drop the default primary key field if any primary key field is defined."""
|
||||
non_default_primary_key_fields = [
|
||||
field_name
|
||||
for field_name, field in cls.__fields__.items()
|
||||
for field_name, field in cls.model_fields.items()
|
||||
if field_name != "id"
|
||||
and getattr(field.field_info, "primary_key", None) is True
|
||||
]
|
||||
if non_default_primary_key_fields:
|
||||
cls.__fields__.pop("id", None)
|
||||
cls.model_fields.pop("id", None)
|
||||
|
||||
super().__init_subclass__()
|
||||
|
||||
@ -95,9 +95,9 @@ class Model(Base, sqlmodel.SQLModel):
|
||||
Returns:
|
||||
The object as a dictionary.
|
||||
"""
|
||||
base_fields = {name: getattr(self, name) for name in self.__fields__}
|
||||
base_fields = {name: getattr(self, name) for name in self.model_fields}
|
||||
relationships = {}
|
||||
# SQLModel relationships do not appear in __fields__, but should be included if present.
|
||||
# SQLModel relationships do not appear in model_fields, but should be included if present.
|
||||
for name in self.__sqlmodel_relationships__:
|
||||
try:
|
||||
relationships[name] = self._dict_recursive(getattr(self, name))
|
||||
|
@ -760,7 +760,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
||||
Raises:
|
||||
NameError: if a variable of this name already exists
|
||||
"""
|
||||
if name in cls.__fields__:
|
||||
if name in cls.model_fields:
|
||||
raise NameError(
|
||||
f"The variable '{name}' already exist. Use a different name"
|
||||
)
|
||||
|
@ -373,7 +373,7 @@ def _extract_class_props_as_ast_nodes(
|
||||
# with the annotation in some cases.
|
||||
with contextlib.suppress(AttributeError, KeyError):
|
||||
# Try to get default from pydantic field definition.
|
||||
default = target_class.__fields__[name].default
|
||||
default = target_class.model_fields[name].default
|
||||
if isinstance(default, Var):
|
||||
default = default._decode() # type: ignore
|
||||
|
||||
|
@ -45,7 +45,7 @@ def test_default_primary_key(model_default_primary):
|
||||
Args:
|
||||
model_default_primary: Fixture.
|
||||
"""
|
||||
assert "id" in model_default_primary.__class__.__fields__
|
||||
assert "id" in model_default_primary.__class__.model_fields
|
||||
|
||||
|
||||
def test_custom_primary_key(model_custom_primary):
|
||||
@ -54,7 +54,7 @@ def test_custom_primary_key(model_custom_primary):
|
||||
Args:
|
||||
model_custom_primary: Fixture.
|
||||
"""
|
||||
assert "id" not in model_custom_primary.__class__.__fields__
|
||||
assert "id" not in model_custom_primary.__class__.model_fields
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings(
|
||||
|
Loading…
Reference in New Issue
Block a user