Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] __fields__ is deprecated, use model_fields instead #6629

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading