Skip to content

Commit

Permalink
fix(base_http): prevent AttributeError when no model object is returned
Browse files Browse the repository at this point in the history
Not every object returned by the UDM REST API is mapped as an OpenAPI model.
Therefore don't expect this when using things only for logging.

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/fastapi/applications.py", line 270, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/base.py", line 106, in __call__
    response = await self.dispatch_func(request, call_next)
  File "/usr/lib/python3.8/site-packages/fastapi_utils/timing.py", line 47, in timing_middleware
    response = await call_next(request)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/base.py", line 80, in call_next
    raise app_exc
  File "/usr/lib/python3.8/site-packages/starlette/middleware/base.py", line 69, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/usr/lib/python3.8/site-packages/asgi_correlation_id/middleware.py", line 81, in __call__
    await self.app(scope, receive, handle_outgoing_request)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/usr/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/usr/lib/python3.8/site-packages/fastapi/routing.py", line 235, in app
    raw_response = await run_endpoint_function(
  File "/usr/lib/python3.8/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
    return await dependant.call(**values)
  File "/kelvin/kelvin-api/ucsschool/kelvin/routers/user.py", line 1286, in complete_update
    user_current = await change_school(udm, logger, user_current, new_school, new_schools.copy())
  File "/kelvin/kelvin-api/ucsschool/kelvin/routers/user.py", line 879, in change_school
    await user.change_school(new_school, udm)
  File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 326, in change_school
    res = await super(ImportUser, self).change_school(school, lo)
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 809, in change_school
    return await self.move(lo, force=True)
  File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 1178, in move
    return await super(ImportUser, self).move(lo, udm_obj, force)
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 761, in move
    success = await self.move_without_hooks(lo, udm_obj, force)
  File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 1185, in move_without_hooks
    return await super(ImportUser, self).move_without_hooks(lo, udm_obj, force)
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 781, in move_without_hooks
    await self.do_move(udm_obj, lo)
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 794, in do_move
    await udm_obj.save()
  File "/usr/lib/python3.8/site-packages/udm_rest_client/base_http.py", line 704, in save
    api_obj = await self._move(self.position, language=language)
  File "/usr/lib/python3.8/site-packages/udm_rest_client/base_http.py", line 871, in _move
    new_api_obj, status, header = await self._udm_module.session.call_openapi(
  File "/usr/lib/python3.8/site-packages/udm_rest_client/base_http.py", line 457, in call_openapi
    _dn = None if status == 204 else api_model_obj.dn
AttributeError: 'dict' object has no attribute 'dn'
  • Loading branch information
spaceone committed Nov 29, 2022
1 parent 7b0ef9b commit fd50cdf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion udm_rest_client/base_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ async def call_openapi( # noqa: C901
return api_model_obj.embedded.udmobject, status, header
else:
# resource
_dn = None if status == 204 else api_model_obj.dn
_dn = None if status == 204 else getattr(api_model_obj, "dn", None)
logger.debug(
"%r %r -> %s(**%r) -> %s(%r) [%r]",
operation,
Expand Down

0 comments on commit fd50cdf

Please sign in to comment.