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

OpenAPI v3 Handling Issue #492

Open
mmangione opened this issue Apr 9, 2024 · 2 comments
Open

OpenAPI v3 Handling Issue #492

mmangione opened this issue Apr 9, 2024 · 2 comments

Comments

@mmangione
Copy link

Hello,

We have had a BlackSheep app running for over a year. When we attempted to upgrade to 2.0.7, we ran into this error. It seems to be an error in the fundamental OpenAPI class. Since this was working fine until today, I think that it must be a bug in 1.0.9.

Here is the error message:

  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 307, in _get_array_outer_type
    return field_info.outer_type_
AttributeError: 'FieldInfo' object has no attribute 'outer_type_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/application.py", line 726, in _handle_lifespan
    await self.start()
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/application.py", line 715, in start
    await self.after_start.fire()
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/application.py", line 126, in fire
    await handler(self.context, *args, **kwargs)
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/common.py", line 404, in build_docs
    docs = self.generate_documentation(app)
  File "/home/mistral/llm_server_env/datascience-llm-server/app/docs/handler.py", line 34, in generate_documentation
    paths=self.get_paths(app),
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 449, in get_paths
    own_paths = self.get_routes_docs(app.router, path_prefix)
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 1146, in get_routes_docs
    request_body=self.get_request_body(handler),
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 847, in get_request_body
    content=self._get_body_binder_content_type(body_binder, body_examples),
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 821, in _get_body_binder_content_type
    return {
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 823, in <dictcomp>
    schema=self.get_schema_by_type(body_binder.expected_type),
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 642, in get_schema_by_type
    schema = self._get_schema_by_type(child_type, type_args)
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 663, in _get_schema_by_type
    return self._get_schema_for_class(object_type)
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 567, in _get_schema_for_class
    for field in self.get_fields(object_type):
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 739, in get_fields
    return handler.get_type_fields(
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 342, in get_type_fields
    return [
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 345, in <listcomp>
    self._open_api_v2_field_schema_to_type(
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 297, in _open_api_v2_field_schema_to_type
    return self._get_array_outer_type(field_info)
  File "/home/mistral/llm_server_env/lib/python3.10/site-packages/blacksheep/server/openapi/v3.py", line 311, in _get_array_outer_type
    return List[field_info.annotation.__args__[0]]
AttributeError: type object 'list' has no attribute '__args__'. Did you mean: '__add__'?```
@mmangione
Copy link
Author

We patched this issue by amending L311 in blacksheep/server/openapi/v3.py to read:

return field_info.annotation

@mmangione
Copy link
Author

mmangione commented Apr 22, 2024

In order to ensure compatibility, the final change in the PR is as follows:

return field_info.annotation if type(field_info.annotation) is type else List[field_info.annotation.__args__[0]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant