asosnovsky / Shortumation

[Not Maintained] A better way to write automations in home-assistant without having to install and run a seperate automation engine!
MIT License
298 stars 6 forks source link

Internal Server Error #131

Closed Sku1ly closed 2 years ago

Sku1ly commented 2 years ago

Describe the bug Internal server error when opening web UI.

It might be something in my config file but I am unsure where to look. I have split up my config and automations into separate folders/files.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Web UI'
  2. Click on 'Web UI'
  3. ???
  4. Look at Error message

Expected behavior See UI

Screenshots

image

Desktop (please complete the following information):

Additional context

  File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 269, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 92, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 147, in simple_response
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 93, in __call__
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 670, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 266, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 65, in app
    response = await func(request)
  File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 227, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 162, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/usr/local/lib/python3.9/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/usr/local/lib/python3.9/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/app/src/api/routes/automations.py", line 20, in list_autos
    return ListData(
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1038, in pydantic.main.validate_model
  File "pydantic/fields.py", line 868, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 899, in pydantic.fields.ModelField._validate_sequence_like
  File "/app/src/automations/manager.py", line 25, in find
    yield from load_automation(auto, tags.get(auto.get("id", ""), {}))
AttributeError: 'str' object has no attribute 'get'
ERROR:hypercorn.error:Error in ASGI Framework
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/hypercorn/asyncio/task_group.py", line 21, in _handle
    await invoke_asgi(app, scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/hypercorn/utils.py", line 247, in invoke_asgi
    await app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 269, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 92, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 147, in simple_response
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 93, in __call__
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 670, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 266, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 65, in app
    response = await func(request)
  File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 227, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 162, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/usr/local/lib/python3.9/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/usr/local/lib/python3.9/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/app/src/api/routes/automations.py", line 20, in list_autos
    return ListData(
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1038, in pydantic.main.validate_model
  File "pydantic/fields.py", line 868, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 899, in pydantic.fields.ModelField._validate_sequence_like
  File "/app/src/automations/manager.py", line 25, in find
    yield from load_automation(auto, tags.get(auto.get("id", ""), {}))
AttributeError: 'str' object has no attribute 'get'
asosnovsky commented 2 years ago

hmmm, so based on the error, it seems that Shortumation failed to locate a valid automation file.

yield from load_automation(auto, tags.get(auto.get("id", ""), {}))
AttributeError: 'str' object has no attribute 'get'

means that at least one of the automations is not an object... do you mind sharing a bit more about your setup? are you using split configs?

Sku1ly commented 2 years ago

Yes I am. I have an empty automations.yaml file and config for the split files looks like this

Screenshot_20220807-055319_Home Assistant

Here's an example of my folder structure and an automation

Screenshot_20220807-055530_Home Assistant

HAOS using the Add On store, no docker etc

asosnovsky commented 2 years ago

Ok, I see. In that case this is something I need to fix. I have had a chance to test split configs properly, and now this seems like something that I need to address asap. Related https://github.com/asosnovsky/Shortumation/issues/129

Sku1ly commented 2 years ago

Hmm maybe but I just commented out my automation config so that I was left with a blank automations.yaml and it still did the same thing.

I restarted the add on and I had the same errors before and after.

swap83 commented 2 years ago

I have same problem. https://xxxx.duckdns.org:8123/api/hassio_ingress/C-s7eJ3nyk4ZRgYPW0IlL5qRzXAz33nDZfNva6JWKNw/automations/list richiesta: POST Codice di stato: 500 Internal Server Error Indirizzo remoto: 192.168.2.251:8123 Criterio relativo al referrer: strict-origin-when-cross-origin

in browser: {"detail":"Method Not Allowed"}

asosnovsky commented 2 years ago

Hmm maybe but I just commented out my automation config so that I was left with a blank automations.yaml and it still did the same thing.

I restarted the add on and I had the same errors before and after.

I see. I am undergoing a refactor of the automation loader, gonna add a few tests for empty automation files

asosnovsky commented 2 years ago

I have same problem. https://xxxx.duckdns.org:8123/api/hassio_ingress/C-s7eJ3nyk4ZRgYPW0IlL5qRzXAz33nDZfNva6JWKNw/automations/list richiesta: POST Codice di stato: 500 Internal Server Error Indirizzo remoto: 192.168.2.251:8123 Criterio relativo al referrer: strict-origin-when-cross-origin

in browser: {"detail":"Method Not Allowed"}

Yea, I am gonna try to get the refactor out soon. I had a long work week, but I will try to address these issues asap.

asosnovsky commented 2 years ago

@swap83 @Sku1ly Take a look at the new release v0.6.1

Sku1ly commented 2 years ago

@asosnovsky perfect thank you, straight in after correcting a few missing ID files.

Appreciate the fix

swap83 commented 2 years ago

Thank you. Now it’s work!