Skip to content

Commit

Permalink
data.__fields__ is deprecated - use data.model_fields instead (#6629)
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone authored Aug 19, 2024
1 parent 07d8232 commit 8f7555b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion openbb_platform/core/openbb_core/api/router/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def exclude_fields_from_api(key: str, value: Any):

# if it's a model with nested fields
elif is_model(type_):
for field_name, field in type_.__fields__.items():
for field_name, field in type_.model_fields.items():
extra = getattr(field, "json_schema_extra", None)
if (
extra
Expand Down
18 changes: 10 additions & 8 deletions openbb_platform/core/openbb_core/provider/abstract/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def test(
if is_list:
assert all(
field in data[0]
for field in cls.data_type.__fields__
for field in cls.data_type.model_fields
if field in data[0]
), f"Data must have the correct fields. Expected: {cls.data_type.__fields__} Got: {data[0].__dict__}"
), f"Data must have the correct fields. Expected: {cls.data_type.model_fields} Got: {data[0].__dict__}"
# This makes sure that the data is not transformed yet so that the
# pipeline is implemented correctly. We can remove this assertion if we
# want to be less strict.
Expand All @@ -178,8 +178,8 @@ def test(
), f"Data must not be transformed yet. Expected: {cls.data_type} Got: {type(data[0])}"
else:
assert all(
field in data for field in cls.data_type.__fields__ if field in data
), f"Data must have the correct fields. Expected: {cls.data_type.__fields__} Got: {data.__dict__}"
field in data for field in cls.data_type.model_fields if field in data
), f"Data must have the correct fields. Expected: {cls.data_type.model_fields} Got: {data.__dict__}"
assert (
issubclass(type(data), cls.data_type) is False
), f"Data must not be transformed yet. Expected: {cls.data_type} Got: {type(data)}"
Expand All @@ -200,10 +200,12 @@ def test(
and return_type_args.__origin__ is dict
)
if return_type_is_dict:
return_type_fields = return_type_args.__args__[1].__args__[0].__fields__
return_type_fields = (
return_type_args.__args__[1].__args__[0].model_fields
)
return_type = return_type_args.__args__[1].__args__[0]
else:
return_type_fields = return_type_args.__fields__
return_type_fields = return_type_args.model_fields
return_type = return_type_args

assert len(transformed_data) > 0, "Transformed data must not be empty." # type: ignore
Expand All @@ -220,8 +222,8 @@ def test(
else:
assert all(
field in transformed_data.__dict__
for field in cls.return_type.__fields__
), f"Transformed data must have the correct fields. Expected: {cls.return_type.__fields__} Got: {transformed_data.__dict__}"
for field in cls.return_type.model_fields
), f"Transformed data must have the correct fields. Expected: {cls.return_type.model_fields} Got: {transformed_data.__dict__}"
assert issubclass(
type(transformed_data), cls.data_type
), f"Transformed data must be of the correct type. Expected: {cls.data_type} Got: {type(transformed_data)}"
Expand Down

0 comments on commit 8f7555b

Please sign in to comment.