kolofordjango / kolo

See everything happening in your running Django app. All without leaving VSCode
https://kolo.app
496 stars 14 forks source link

Unexpected Application Error! Got status 500 when requesting GET #92

Open icfly2 opened 3 weeks ago

icfly2 commented 3 weeks ago

When I follow the instructions for gerenating a test on my current app I get this:

Unexpected Application Error!
Got status 500 when requesting GET http://localhost:8000/_kolo/api/generate-test/trc_01J5QSMNXPSJ0TPEAS23A3CY0X/

e/<@http://localhost:8000/_kolo/static/spa/main.js:2:1551065
d@http://localhost:8000/_kolo/static/spa/main.js:2:1541612
zt/_/<@http://localhost:8000/_kolo/static/spa/main.js:2:1542956
zt/R/</<@http://localhost:8000/_kolo/static/spa/main.js:2:1542041
Kt@http://localhost:8000/_kolo/static/spa/main.js:2:1547518
a@http://localhost:8000/_kolo/static/spa/main.js:2:1547724

when trying to generate a test.

I can see the trace as json.

I'm running a very old version of django (3...) . (The idea is to use Kolo to generate tests to make the upgrade less painfull)

Is there a minum version of django you support? Or any other ideas what could cause this error?

wilhelmklopp commented 3 weeks ago

👋 Hey @icfly2

in your django runserver output, does it have more information about what caused the 500?

icfly2 commented 3 weeks ago

This is from the logs:

[21/Aug/2024 16:49:49]; INFO; [django.utils.autoreload:637]; Watching for file changes with StatReloader
[21/Aug/2024 16:50:15]; INFO; [django.server:161]; "GET / HTTP/1.1" 200 8916
[21/Aug/2024 16:50:17]; INFO; [django.server:161]; "GET /tutor_info HTTP/1.1" 301 0
[21/Aug/2024 16:50:22]; INFO; [django.server:161]; "GET /parents_info HTTP/1.1" 200 8131
[21/Aug/2024 16:50:27]; INFO; [django.server:161]; "GET /registration HTTP/1.1" 200 12147
[21/Aug/2024 16:50:55]; ERROR; [django.request:224]; Internal Server Error: /_kolo/api/generate-test/trc_01J5TPNP39XZ8XR1MWCSWPYP3R/
Traceback (most recent call last):
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\sentry_sdk\integrations\django\middleware.py", line 176, in __call__
    return f(*args, **kwargs)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\middleware.py", line 105, in __call__
    return kolo_web_router(request)
  File "C:\Users\Ruben Menke\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\middleware.py", line 320, in kolo_web_router
    return kolo_web_api_generate_test(request)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\middleware.py", line 368, in kolo_web_api_generate_test
    plan = create_test_plan(config, context)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\generate_tests\__init__.py", line 56, in create_test_plan
    plan = Plan(build_steps(context, pytest=pytest), pytest, context)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\generate_tests\plan.py", line 64, in __init__
    self.steps = list(steps)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\generate_tests\plan.py", line 149, in build_steps
    yield from header_comments(context)
  File "C:\Users\Ruben Menke\Documents\site\env\lib\site-packages\kolo\generate_tests\plan.py", line 98, in header_comments
    yield CodeComment(f"Auto generated by Kolo at {context['now']}.")
TypeError: CodeComment() takes no arguments
wilhelmklopp commented 1 week ago

@icfly2 sorry i missed your reply here – I'm a bit perplexed by the error because CodeComment as a concept on our end makes no sense without taking arguments 😅

Are you on the latest version of Kolo (2.33.6) ?

icfly2 commented 6 days ago

Django 3.2.16 kolo 2.33.6 Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32

>pip list

Package            Version
------------------ -----------
anyio              4.4.0
asgiref            3.8.1
attrs              23.2.0
bokeh              2.3.3
Cerberus           1.3.5
certifi            2022.5.18.1
chardet            3.0.4
charset-normalizer 2.0.4
click              7.1.2
colorama           0.4.5
decorator          5.1.1
Django             3.2.16
docopt             0.6.2
dparse             0.5.1
et-xmlfile         1.1.0
exceptiongroup     1.2.2
fancycompleter     0.9.1
greenlet           2.0.2
h11                0.14.0
httpcore           1.0.5
httptools          0.6.1
httpx              0.27.0
idna               3.3
importlib_metadata 8.3.0
Jinja2             2.11.3
kolo               2.33.6
MarkupSafe         2.0.1
mocket             3.12.8
more-itertools     10.4.0
msgpack            1.0.8
mypy-extensions    0.4.3
num2words          0.5.10
numpy              1.21.2
openpyxl           3.0.9
packaging          19.2
pandas             1.1.5
pathspec           0.10.1
pdbpp              0.10.3
Pillow             8.4.0
pip                22.1.2
platformdirs       4.2.2
psycopg2           2.9.3
Pygments           2.17.2
pyparsing          3.0.9
pyreadline         2.1
pyrepl             0.9.0
python-dateutil    2.8.2
python-magic       0.4.27
python-magic-bin   0.4.14
pytz               2022.1
PyYAML             6.0
requests           2.28.1
safety             1.9.0
selenium           3.141.0
Send2Trash         1.5.0
sentry-sdk         1.10.1
setuptools         56.0.0
six                1.16.0
sniffio            1.3.1
SQLAlchemy         2.0.15
sqlglot            25.15.0
sqlparse           0.4.2
tabulate           0.9.0
toml               0.10.2
tomli              2.0.1
toolz              0.12.1
tornado            6.1
typing_extensions  4.2.0
tzdata             2024.1
ulid-py            1.1.0
urllib3            1.26.12
wheel              0.37.1
wmctrl             0.5
xlrd               1.1.0
XlsxWriter         3.0.3
zipp               3.20.0
icfly2 commented 6 days ago

I just made a completly clean project with that django version and kolo version and get the same thing:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
September 08, 2024 - 08:25:24
Django version 3.2.16, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

View recent requests at http://127.0.0.1:8000/_kolo/
Not Found: /sw.js
[08/Sep/2024 08:25:31] "GET /sw.js HTTP/1.1" 404 2092
Internal Server Error: /_kolo/api/generate-test/trc_01J784Y6S9Y9PES1P0PBSY3FKX/
Traceback (most recent call last):
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\middleware.py", line 105, in __call__
    return kolo_web_router(request)
  File "C:\Users\Ruben Menke\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\middleware.py", line 320, in kolo_web_router
    return kolo_web_api_generate_test(request)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\middleware.py", line 368, in kolo_web_api_generate_test
    plan = create_test_plan(config, context)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\generate_tests\__init__.py", line 56, in create_test_plan
    plan = Plan(build_steps(context, pytest=pytest), pytest, context)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\generate_tests\plan.py", line 64, in __init__
    self.steps = list(steps)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\generate_tests\plan.py", line 149, in build_steps
    yield from header_comments(context)
  File "C:\Users\Ruben Menke\Documents\kolotrial\env\lib\site-packages\kolo\generate_tests\plan.py", line 98, in header_comments
    yield CodeComment(f"Auto generated by Kolo at {context['now']}.")
TypeError: CodeComment() takes no arguments
Not Found: /sw.js

does kolo use /sw.js ?

The original website has a PWA component (as i said its old), might that be interfearing?

wilhelmklopp commented 5 days ago

@icfly2 appreciate all the additional details! I'm still pretty stumped to be honest – CodeComment is literally just a dataclass, so the error makes no sense to me.

This is the code:

class Step(Protocol):
    indent_delta: ClassVar[int] = 0

    def render(self, pytest: bool) -> str: ...  # pragma: no branch

    def get_imports(self, pytest: bool) -> Set["Import"]:
        return set()

    @classmethod
    def get_steps(cls, steps: List["Step"]) -> List[Tuple[slice, List["Step"]]]:
        selected = []
        for index, step in enumerate(steps):
            if isinstance(step, cls):
                selected.append((slice(index, index + 1), [step]))
        return selected

@dataclass()
class CodeComment(Step):
    comment: str

    def render(self, pytest):
        return f"# {self.comment}\n"

If you do the following, do you get the same error?

>>> from kolo.generate_tests.steps import CodeComment
>>> CodeComment("hello world")
CodeComment(comment='hello world'

Also happy to jump on a call together to dig in more: https://savvycal.com/wil