Custom API tool sends unset optional header and cookie parameters as empty values or "None"
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 77/100
Research direction
Start in api/core/tools/custom_tool/tool.py at ApiTool.do_http_request and trace how get_parameter_value handles optional query, header, and cookie parameters with missing or null defaults. Check the related custom tool tests and add coverage for omitted optional values and boolean headers. Done means empty and None values are omitted for optional parameters, while a boolean header is sent as lowercase true.
Written by the indexing model from the issue text.
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
main (b63ed037d0)
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
- Create a custom tool (Tools → Custom → Create Custom Tool) from this schema:
openapi: 3.0.0
info: {title: demo, version: "1"}
servers: [{url: https://httpbin.org}]
paths:
/anything:
get:
operationId: listItems
parameters:
- {name: X-Request-Id, in: header, required: false, schema: {type: string}}
- {name: X-Tenant, in: header, required: false, schema: {type: string, default: null}}
- {name: X-Dry-Run, in: header, required: false, schema: {type: boolean}}
- {name: session, in: cookie, required: false, schema: {type: string}}
- Test the
listItemstool with onlyX-Dry-Run = truefilled in (leave the other parameters empty).
✔️ Expected Behavior
Optional header and cookie parameters that have no value are left out, as optional query parameters already are. A boolean header is sent as true, which is how the tool already sends a boolean query parameter (?flag=true).
X-Dry-Run: true
❌ Actual Behavior
Every declared header and cookie is sent, even when it has no value. A default: null is sent as the text None, and a boolean is sent as Python's True:
X-Request-Id:
X-Tenant: None
X-Dry-Run: True
Cookie: session=
APIs that validate these headers then reject the call or treat the value as real, for example a tenant named None or an empty session cookie that replaces the anonymous one.
In ApiTool.do_http_request (api/core/tools/custom_tool/tool.py), query parameters are skipped when get_parameter_value returns "". Header parameters are always set to str(value), and cookie parameters are always set to the raw value. get_parameter_value returns "" for an optional parameter without a default, and returns the schema default (here None) otherwise. A default: null query parameter is affected too: None is not "", so it is sent as ?q=.
- Dominant language
- Python
- Stars
- 160k
- Forks
- 25.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 608
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/dify
-
Detail sidebar collapse drops keyboard focusPossibly taken @GYJ99 claimed this 1 day ago. Openproject#dify
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
langgenius/dify#45934 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
[Bug] CotAgentOutputParser overwrites action_name with non-input keys and collapses multi-block code fencesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
langgenius/dify#45324 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
[Chore/Refactor] bring jieba keyword table handler tests under strict pyreflyMay be free again @Luckyou-d claimed this 7 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
langgenius/dify#45319 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] Agent resource access page loses its sidebar on refreshPossibly taken @XiaoBa-Yu claimed this 8 days ago. Open1.18.0
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
langgenius/dify#45291 · 1 reaction ·
Maintainers usually reply within 1 day
-
Parent-child full-doc mode raises IndexError when extraction yields zero documentsPossibly taken @simpleqt claimed this 9 days ago. Open1.18.0
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
langgenius/dify#45272 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
With emit_ontology_keys, one ontology key change is reported as two errors (keys and keys_digest)Possibly taken @rvandewater claimed this today. Openbug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
iausathub/satchecker#286 ·
Maintainers usually reply within 1 day
-
bug test
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenAssetIO/OpenAssetIO#1527 ·
-
automated endpoint-dead needs-curation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
almanac-data/climate-almanac#128 ·
Maintainers usually reply within 1 day