kolofordjango/kolo

Error while generating trace using kolo

Closed this issue · 12 comments

Using kolo v2.12.1

E AttributeError: ‘function’ object has no attribute ‘as_view’. or E AttributeError: 'function' object has no attribute 'get_extra_actions'

Command used:
kolo run --one-trace-per-test pytest <test_file>

Hi! Do you have a full traceback? Or is this coming from the rust extension?

app/urls.py:189: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <rest_framework.routers.DefaultRouter object at 0x7f88c58f3100>

    @property
    def urls(self):
        if not hasattr(self, '_urls'):
>           self._urls = self.get_urls()

/venv/lib/python3.9/site-packages/rest_framework/routers.py:77: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <rest_framework.routers.DefaultRouter object at 0x7f88c58f3100>

    def get_urls(self):
        """
        Generate the list of URL patterns, including a default root view
        for the API, and appending `.json` style format suffixes.
        """
>       urls = super().get_urls()

/venv/lib/python3.9/site-packages/rest_framework/routers.py:338: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <rest_framework.routers.DefaultRouter object at 0x7f88c58f3100>

    def get_urls(self):
        """
        Use the registered viewsets to generate a list of URL patterns.
        """
        ret = []
    
        for prefix, viewset, basename in self.registry:
            lookup = self.get_lookup_regex(viewset)
>           routes = self.get_routes(viewset)

/venv/lib/python3.9/site-packages/rest_framework/routers.py:236: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <rest_framework.routers.DefaultRouter object at 0x7f88c58f3100>, viewset = <function ApplicationViewSet at 0x7f88c5b59550>

    def get_routes(self, viewset):
        """
        Augment `self.routes` with any dynamically generated routes.
    
        Returns a list of the Route namedtuple.
        """
        # converting to list as iterables are good for one pass, known host needs to be checked again and again for
        # different functions.
        known_actions = list(flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)]))
>       extra_actions = viewset.get_extra_actions()
E       AttributeError: 'function' object has no attribute 'get_extra_actions'

/venv/lib/python3.9/site-packages/rest_framework/routers.py:152: AttributeError

During handling of the above exception, another exception occurred:

self = <file_name testMethod=test_list>

    def test_list(self):
>       response = self.client.get(<endpoint>)
 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/venv/lib/python3.9/site-packages/rest_framework/test.py:289: in get
    response = super().get(path, data=data, **extra)
/venv/lib/python3.9/site-packages/rest_framework/test.py:206: in get
    return self.generic('GET', path, **r)
/venv/lib/python3.9/site-packages/rest_framework/test.py:234: in generic
    return super().generic(
/venv/lib/python3.9/site-packages/django/test/client.py:473: in generic
    return self.request(**r)
/venv/lib/python3.9/site-packages/rest_framework/test.py:286: in request
    return super().request(**kwargs)
/venv/lib/python3.9/site-packages/rest_framework/test.py:238: in request
    request = super().request(**kwargs)
/venv/lib/python3.9/site-packages/django/test/client.py:714: in request
    response = self.handler(environ)
/venv/lib/python3.9/site-packages/django/test/client.py:145: in __call__
    response = self.get_response(request)
/venv/lib/python3.9/site-packages/rest_framework/test.py:258: in get_response
    return super().get_response(request)
/venv/lib/python3.9/site-packages/django/core/handlers/base.py:130: in get_response
    response = self._middleware_chain(request)
/venv/lib/python3.9/site-packages/django/core/handlers/exception.py:49: in inner
    response = response_for_exception(request, exc)
/venv/lib/python3.9/site-packages/django/core/handlers/exception.py:114: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
/venv/lib/python3.9/site-packages/django/core/handlers/exception.py:152: in handle_uncaught_exception
    callback = resolver.resolve_error_handler(500)
/venv/lib/python3.9/site-packages/django/urls/resolvers.py:615: in resolve_error_handler
    callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
/venv/lib/python3.9/site-packages/django/utils/functional.py:48: in __get__
    res = instance.__dict__[self.name] = self.func(instance)
/venv/lib/python3.9/site-packages/django/urls/resolvers.py:595: in urlconf_module
    return import_module(self.urlconf_name)
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:850: in exec_module
    ???
<frozen importlib._bootstrap>:228: in _call_with_frames_removed
    ???
app/urls.py:189: in <module>
    re_path(r"^", include(router.urls)),
/venv/lib/python3.9/site-packages/rest_framework/routers.py:77: in urls
    self._urls = self.get_urls()
/venv/lib/python3.9/site-packages/rest_framework/routers.py:338: in get_urls
    urls = super().get_urls()
/venv/lib/python3.9/site-packages/rest_framework/routers.py:236: in get_urls
    routes = self.get_routes(viewset)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <rest_framework.routers.DefaultRouter object at 0x7f88c6b0dee0>, viewset = <function ApplicationViewSet at 0x7f88c5b59550>

    def get_routes(self, viewset):
        """
        Augment `self.routes` with any dynamically generated routes.
    
        Returns a list of the Route namedtuple.
        """
        # converting to list as iterables are good for one pass, known host needs to be checked again and again for
        # different functions.
        known_actions = list(flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)]))
>       extra_actions = viewset.get_extra_actions()
E       AttributeError: 'function' object has no attribute 'get_extra_actions'

/venv/lib/python3.9/site-packages/rest_framework/routers.py:152: AttributeError`

Can you confirm that the test passes without kolo?

Actually, it looks like this might be your problem: https://stackoverflow.com/a/52490842

Can you confirm that the test passes without kolo?

Yes, tests run fine without kolo

Can you share a working example, including your views, urls and test code?

also have this problem ( ╯□╰ )
python package kolo v2.11.0 is ok, but update to v2.12.0 can't trace , then degrade to v2.11.0 is work again

VScode kolo version : v2.7.0

2023-07-14 09_56_17-interview_record_form py - recruit - Visual Studio Code

@we684123 Today I released 2.12.3 - can you let me know if you still see this with that version?

@LilyFoote thank you update v2.12.3 , but is not fixed 〒▽〒

2023-07-17 08_59_07-Greenshot


here is a minimal realization for reproduce

poetry init 
poetry add django
poetry add kolo@2.11.0 --group dev
poetry shell
django-admin startproject for_kolo_debug

( Move creation to previous folder )
2023-07-17 09_14_53-for_kolo

add 'kolo.middleware.KoloMiddleware' to setting MIDDLEWARE link:

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    'kolo.middleware.KoloMiddleware',
]
python manage.py migrate
python manage.py runserver 127.0.0.1:8002

( open http://127.0.0.1:8002/ web)
( can trace )
( 'ctrl + C' to close python )

p add kolo@2.12.3 --group dev
python manage.py runserver 127.0.0.1:8002

( open http://127.0.0.1:8002/ web )
( can't trace )

@we684123 Thanks! I think I've fully fixed it this time around with 2.12.4.

@LilyFoote Thank you~ very much~ now is working
kolo v2.9.0 (VScode)
kolo v2.12.4 (Python)
13

@vaibhavnagda Let me know if you still see this failure.