Maillol / aiohttp-pydantic

Aiohttp View that validates request body and query sting regarding the annotations declared in the View method
MIT License
67 stars 21 forks source link

UnboundLocalError: cannot access local variable 'method_name' where it is not associated with a value #68

Closed tonal closed 2 months ago

tonal commented 2 months ago

class ViewSelfcheck(ViewBase):
  async def get(self) -> r200[RspOk]:
    return {'status': 'Ok'}

app = web.Application()
app.router.add_get('/selfcheck/', ViewSelfcheck, allow_head=False)
oas.setup(app)

After get Swagger - error:

...
  File "/home/user/props_service/venv/lib/python3.12/site-packages/aiohttp_pydantic/oas/view.py", line 242, in get_oas
    return json_response(generate_oas(apps, version_spec, title_spec, security))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/props_service/venv/lib/python3.12/site-packages/aiohttp_pydantic/oas/view.py", line 201, in generate_oas
    handler = getattr(view, method_name.lower())
                            ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'method_name' where it is not associated with a value