KeyError: 'position'
Self Checks
- [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [X] Please do not modify this template :) and fill in all the required fields.
Dify version
0.9.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
edge error:
[2024-10-08 09:44:55 +0000] [41] [ERROR] Error handling request
Traceback (most recent call last):
File "/app/api/.venv/lib/python3.10/site-packages/gunicorn/workers/base_async.py", line 115, in handle_request
for item in respiter:
File "/app/api/.venv/lib/python3.10/site-packages/werkzeug/wsgi.py", line 256, in __next__
return self._next()
File "/app/api/.venv/lib/python3.10/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded
for item in iterable:
File "/app/api/.venv/lib/python3.10/site-packages/flask/helpers.py", line 113, in generator
yield from gen
File "/app/api/libs/helper.py", line 185, in generate
yield from response
File "/app/api/core/app/features/rate_limiting/rate_limit.py", line 115, in __next__
return next(self.generator)
File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 38, in _generate_simple_response
for chunk in cls.convert_stream_simple_response(response):
File "/app/api/core/app/apps/chat/generate_response_converter.py", line 111, in convert_stream_simple_response
sub_stream_response_dict["metadata"] = cls._get_simple_metadata(metadata)
File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 84, in _get_simple_metadata
"position": resource["position"],
KeyError: 'position'
✔️ Expected Behavior
No response
❌ Actual Behavior
No response
@eraizi Hello there! I'm here to help you with bug fixes, answer questions, and guide you on becoming a contributor. Let's tackle this issue together!
The KeyError: 'position' indicates that the code is trying to access the 'position' key in a dictionary, but it doesn't exist. This error occurs in the _get_simple_metadata method within the base_app_generate_response_converter.py file.
To resolve this issue, you should ensure that the 'position' key is present in the resource dictionary before accessing it. You can add a check to see if the key exists or use the get method to provide a default value if the key is missing.
Here's a possible modification:
"position": resource.get("position", default_value)
Replace default_value with an appropriate default if the 'position' key is not always guaranteed to be present. This will prevent the KeyError from occurring.
To continue talking to Dosu, mention @dosu.
Hi @eraizi! Thank you for your report. Can you provide a minimal DSL that can reproduce this issue?