aiohttp-cors icon indicating copy to clipboard operation
aiohttp-cors copied to clipboard

TypeError: issubclass() arg 1 must be a class when initialize my app with new relic

Open gabriellydeandrade opened this issue 5 years ago • 1 comments

I am using aiohttp and initializing new relic in my __main__ file this way:

import newrelic.agent

if config.NEW_RELIC_SETTED:
    newrelic.agent.initialize()

# some initializations ...
web.run_app(app)

Api is the class that I am using aiohttp and initializing my session, web.Application, cors setup and so on

However, when I run my application the following error ocours:

Traceback (most recent call last):
  File "/home/gabrielly.silva/sieve/api_portal/app/__main__.py", line 12, in <module>
    Api().start()
  File "/home/gabrielly.silva/sieve/api_portal/app/api.py", line 41, in __init__
    self.register_routes()
  File "/home/gabrielly.silva/sieve/api_portal/app/api.py", line 90, in register_routes
    self.cors.add(route)
  File "/home/gabrielly.silva/sieve/api_portal/.venv/lib/python3.7/site-packages/aiohttp_cors/cors_config.py", line 263, in add
    return self._cors_impl.add(routing_entity, config)
  File "/home/gabrielly.silva/sieve/api_portal/.venv/lib/python3.7/site-packages/aiohttp_cors/cors_config.py", line 135, in add
    routing_entity, self._preflight_handler)
  File "/home/gabrielly.silva/sieve/api_portal/.venv/lib/python3.7/site-packages/aiohttp_cors/urldispatcher_router_adapter.py", line 195, in add_preflight_handler
    self.add_preflight_handler(route.resource, handler)
  File "/home/gabrielly.silva/sieve/api_portal/.venv/lib/python3.7/site-packages/aiohttp_cors/urldispatcher_router_adapter.py", line 165, in add_preflight_handler
    if _is_web_view(route_obj):
  File "/home/gabrielly.silva/sieve/api_portal/.venv/lib/python3.7/site-packages/aiohttp_cors/urldispatcher_router_adapter.py", line 95, in _is_web_view
    if isinstance(handler, type) and issubclass(handler, web.View):
  File "/usr/lib/python3.7/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

In the point that the function __is_web_view_ compares if handler is a subclasse of web.View, the handler is wrapped by new relic

$ type(handler) <class 'newrelic.common.object_wrapper.FunctionWrapper'>

Is there a way that I can work around and solve this?

Thanks

gabriellydeandrade avatar Jan 10 '19 14:01 gabriellydeandrade

Guys from newrelic are working on this issue on their side. They proposed a workaround. Put the following into your newrelic.ini:

[import-hook:aiohttp.web_urldispatcher]
enabled = false

which will address the issue and allow you to use the agent. The only side effect, in this case, is that the transaction naming might look a bit different.

xdrew avatar Jan 23 '20 11:01 xdrew