Incorrect Dictionary Key Access Causing AttributeError in _upload_file_to_tongyi Method #281

Closed
opened 2026-02-16 10:18:47 -05:00 by yindo · 2 comments
Owner

Originally created by @cmlibo on GitHub (May 15, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.3.1

Plugin version

0.0.25

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Description:

The _upload_file_to_tongyi method incorrectly accesses the dashscope_api_key value using dot notation (credentials.dashscope_api_key) instead of dictionary key syntax, resulting in an AttributeError when credentials is passed as a dict.

Steps to Reproduce:

Call the _upload_file_to_tongyi method with credentials as a Python dictionary (e.g., {"dashscope_api_key": "YOUR_KEY"}).
The code will fail at this line:

client = OpenAI(
api_key=credentials.dashscope_api_key, # Incorrect access
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
Error:

AttributeError: 'dict' object has no attribute 'dashscope_api_key'
Expected Behavior:

The code should access the dashscope_api_key value using dictionary key syntax (credentials["dashscope_api_key"]).

Suggested Fix:

Replace credentials.dashscope_api_key with credentials["dashscope_api_key"] in the _upload_file_to_tongyi method:

client = OpenAI( api_key=credentials["dashscope_api_key"], # Correct access base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", )

✔️ Error log

[tongyi] Error: PluginInvokeError: {"args":{"description":"[models] Error: 'dict' object has no attribute 'dashscope_api_key'"},"error_type":"InvokeError","message":"[models] Error: 'dict' object has no attribute 'dashscope_api_key'"}

Originally created by @cmlibo on GitHub (May 15, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.3.1 ### Plugin version 0.0.25 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Description: The _upload_file_to_tongyi method incorrectly accesses the dashscope_api_key value using dot notation (credentials.dashscope_api_key) instead of dictionary key syntax, resulting in an AttributeError when credentials is passed as a dict. Steps to Reproduce: Call the _upload_file_to_tongyi method with credentials as a Python dictionary (e.g., {"dashscope_api_key": "YOUR_KEY"}). The code will fail at this line: <PYTHON> client = OpenAI( api_key=credentials.dashscope_api_key, # ❌ Incorrect access base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", ) Error: <PYTHON> AttributeError: 'dict' object has no attribute 'dashscope_api_key' Expected Behavior: The code should access the dashscope_api_key value using dictionary key syntax (credentials["dashscope_api_key"]). Suggested Fix: Replace credentials.dashscope_api_key with credentials["dashscope_api_key"] in the _upload_file_to_tongyi method: <PYTHON> client = OpenAI( api_key=credentials["dashscope_api_key"], # ✅ Correct access base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", ) ### ✔️ Error log [tongyi] Error: PluginInvokeError: {"args":{"description":"[models] Error: 'dict' object has no attribute 'dashscope_api_key'"},"error_type":"InvokeError","message":"[models] Error: 'dict' object has no attribute 'dashscope_api_key'"}
yindo added the bug label 2026-02-16 10:18:47 -05:00
yindo closed this issue 2026-02-16 10:18:47 -05:00
Author
Owner

@aaditiiiii1 commented on GitHub (May 20, 2025):

Hi @cmlibo ,
I'd like to take this issue and submit a fix.

Bug Summary

The _upload_file_to_tongyi method currently accesses the API key like this:

api_key = credentials.dashscope_api_key  #  Incorrect

When credentials is a dictionary, this causes:
AttributeError: 'dict' object has no attribute 'dashscope_api_key'

Summary of Planned Changes:

I will modify the code to correctly use dictionary key access:

api_key = credentials["dashscope_api_key"]  #  Correct

This fix will be made in the following file:
models/tongyi/models/llm/llm.py

Attaching an image for the changes I propose.

Image

Please assign this issue to me.
Let me know if there’s anything else I should consider or if I’ve misunderstood the scope. Thank you!

@aaditiiiii1 commented on GitHub (May 20, 2025): Hi @cmlibo , I'd like to take this issue and submit a fix. ## Bug Summary The `_upload_file_to_tongyi` method currently accesses the API key like this: ```python api_key = credentials.dashscope_api_key # Incorrect ``` **When credentials is a dictionary, this causes:** AttributeError: 'dict' object has no attribute 'dashscope_api_key' ## **Summary of Planned Changes:** I will modify the code to correctly use dictionary key access: ``` api_key = credentials["dashscope_api_key"] # Correct ``` **This fix will be made in the following file:** models/tongyi/models/llm/llm.py Attaching an image for the changes I propose. <img width="470" alt="Image" src="https://github.com/user-attachments/assets/556bffd2-5211-4580-977e-55355a670414" /> Please assign this issue to me. Let me know if there’s anything else I should consider or if I’ve misunderstood the scope. Thank you!
Author
Owner

@dosubot[bot] commented on GitHub (Aug 18, 2025):

Hi, @cmlibo. I'm Dosu, and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported an AttributeError caused by incorrect dot notation access of dashscope_api_key on a dictionary in the _upload_file_to_tongyi method.
  • Contributor codequartz1 proposed a fix by changing credentials.dashscope_api_key to credentials["dashscope_api_key"].
  • I implemented the fix in models/tongyi/models/llm/llm.py.
  • No further comments or concerns have been raised since the fix.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here.
  • If no response is received, I will automatically close this issue in 5 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 18, 2025): Hi, @cmlibo. I'm [Dosu](https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported an AttributeError caused by incorrect dot notation access of `dashscope_api_key` on a dictionary in the `_upload_file_to_tongyi` method. - Contributor codequartz1 proposed a fix by changing `credentials.dashscope_api_key` to `credentials["dashscope_api_key"]`. - I implemented the fix in `models/tongyi/models/llm/llm.py`. - No further comments or concerns have been raised since the fix. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here. - If no response is received, I will automatically close this issue in 5 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#281