Unexpected error while viewing minions / comformity list
duhow opened this issue ยท 7 comments
Describe the bug
Unexpected Django error appeared in logs while viewing conformity list of a machine, and list of minions.
Apparently caused by a single machine status. Differs from #505
This is blocking to display all minion list.
๐ Logs
Internal Server Error: /api/conformity/render/
Traceback (most recent call last):
File "/opt/alcali/.local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/opt/alcali/.local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/api/views/alcali.py", line 241, in render
if last_highstate[state]["result"] is True:
TypeError: string indices must be integers
[21/Oct/2023 03:34:30] "GET /api/conformity/render/ HTTP/1.1" 500 99100
last_highstate 'Unhandled exception running state.apply'
Traceback (most recent call last):
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/fields.py", line 102, in get_attribute
instance = instance()
File "/opt/alcali/.local/lib/python3.9/site-packages/api/models.py", line 173, in conformity
if not return_item.get(state, {}).get("result"):
During handling of the above exception ('str' object has no attribute 'get'), another exception occurred:
File "/opt/alcali/.local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/opt/alcali/.local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/mixins.py", line 46, in list
return Response(serializer.data)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/serializers.py", line 768, in data
ret = super().data
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/serializers.py", line 253, in data
self._data = self.to_representation(self.instance)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/serializers.py", line 686, in to_representation
return [
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/serializers.py", line 687, in <listcomp>
self.child.to_representation(item) for item in iterable
File "/opt/alcali/.local/lib/python3.9/site-packages/api/serializers.py", line 70, in to_representation
data = super(MinionsSerializer, self).to_representation(instance)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/serializers.py", line 509, in to_representation
attribute = field.get_attribute(instance)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/fields.py", line 457, in get_attribute
return get_attribute(instance, self.source_attrs)
File "/opt/alcali/.local/lib/python3.9/site-packages/rest_framework/fields.py", line 107, in get_attribute
raise ValueError('Exception raised in callable attribute "{}"; original exception was: {}'.format(attr, exc))
Exception Type: ValueError at /api/minions/
Exception Value: Exception raised in callable attribute "conformity"; original exception was: 'str' object has no attribute 'get'
Version 3003.1.0
so we can close it right?
Sorry, but faced this issue again with latest commit.
Apparently this appeared when adding a new minion? Let me get more details on the issue...
line 174, in conformity
https://github.com/latenighttales/alcali/blob/v3006.3.0/api/models.py#L174
('str' object has no attribute 'get')
I think this is the cause for the "string":
tag: salt/job/20231024100007873742/ret/midokura-lap127
{"cmd": "_return", "id": "midokura-lap127", "fun": "state.apply", "fun_args": [], "schedule": "salt-apply", "jid": "20231024100007873742", "pid": 22179, "return": "Unhandled exception running state.apply", "success": false, "retcode": 254, "_stamp": "2023-10-24T10:00:07.878783", "out": "highstate", "arg": [], "tgt_type": "glob", "tgt": "midokura-lap127"}
return
is a string.
diff --git a/api/models.py b/api/models.py
index de799c4..0ef5260 100644
--- a/api/models.py
+++ b/api/models.py
@@ -171,6 +171,8 @@ class Minions(models.Model):
for state in return_item:
# One of the state is not ok
+ if isinstance(return_item, str):
+ return False
if not return_item.get(state, {}).get("result"):
return False
return True
This works for me ๐๐ป
Sounds good ๐
Do you mind opening a PR?