Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error while viewing minions / comformity list #510

Open
duhow opened this issue Oct 21, 2023 · 7 comments · May be fixed by #515
Open

Unexpected error while viewing minions / comformity list #510

duhow opened this issue Oct 21, 2023 · 7 comments · May be fixed by #515
Labels
bug Something isn't working

Comments

@duhow
Copy link
Contributor

duhow commented Oct 21, 2023

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

@duhow duhow added the bug Something isn't working label Oct 21, 2023
@duhow
Copy link
Contributor Author

duhow commented Oct 21, 2023

✅ Works with latest commit 3c45215 .

@mattLLVW
Copy link
Contributor

so we can close it right?

@duhow duhow closed this as completed Oct 21, 2023
@duhow
Copy link
Contributor Author

duhow commented Oct 24, 2023

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...

@duhow duhow reopened this Oct 24, 2023
@duhow
Copy link
Contributor Author

duhow commented Oct 24, 2023

line 174, in conformity
https://github.com/latenighttales/alcali/blob/v3006.3.0/api/models.py#L174

('str' object has no attribute 'get')

@duhow
Copy link
Contributor Author

duhow commented Oct 24, 2023

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.

@duhow
Copy link
Contributor Author

duhow commented Oct 24, 2023

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 👍🏻

@mattLLVW
Copy link
Contributor

Sounds good 😊
Do you mind opening a PR?

@duhow duhow linked a pull request Oct 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants