export_service! macro should correctly name records wrapped in `ManualReply`s
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rust
- Domain
- api, backend-api-design
Research direction
Reproduce the issue with the Rust example using candid::export_service! and run cargo test to inspect the generated test.did file. Start by tracing how export_service! handles ManualReply return types; done means the generated candid names the wrapped record User rather than ManualReply or an incremented variant.
Written by the indexing model from the issue text.
Description
Describe the bug
The candid export service doesn't correctly handle canister methods with a return type of ManualReply. Instead of exporting the record type in the canister method signature, it exports a generic ManualReply type. Subsequent ManualReplys will be given incrementing names of format ManualReply_n where n increases for the amount of records.
To Reproduce
Steps to reproduce the behavior:
-
Create a Rust canister with the following contents:
use ic_cdk::api::call::{self, ManualReply}; #[derive(candid::CandidType)] struct User { id: String, } #[ic_cdk_macros::query] #[candid::candid_method(query)] async fn method() -> ManualReply<User> { let user = User { id: "a".to_string(), }; call::reply((user,)); ManualReply::empty() } candid::export_service!(); #[ic_cdk_macros::query(name = "__get_candid_interface_tmp_hack")] fn export_candid() -> String { __export_service() } #[cfg(test)] mod tests { use super::*; #[test] fn write_candid_to_disk() { std::fs::write("test.did", export_candid()).unwrap(); } }Full example can be found at https://github.com/dansteren/candid_export_bug
-
Run
cargo test -
Inspect the generated candid file at canisters/tests/test.did
-
Notice that it contains a type
ManualReplywhich doesn't have the same name as theUserstruct in canisters/test/src/lib.rstype ManualReply = record { id : text }; service : { method : () -> (ManualReply) query }
Expected behavior
The candid file should name the user type User not ManualReply. I.e.
type User = record { id : text };
service : { method : () -> (User) query }
Screenshots
N/A
Platform
- OS: Ubuntu 22.04
- Rust Version: rustc 1.63.0 (4b91a6ea7 2022-08-08)
- DFX Version: 0.11.0
- Candid Crate Version: 0.7.4
Additional context
The problem occurs regardless of whether the function is a Query or an Update. The problem does not occur if another function also returns that type (See https://github.com/dansteren/candid_export_bug/tree/include_type_in_other_function_sig).
PS: Your Bug issue template isn't working so I was unable to apply the Bug label.
- Dominant language
- Rust
- Stars
- 301
- Forks
- 85
- Avg merge
- 1h 4m
- Merged PRs (30d)
- 4
Contributor 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 dfinity/candid
-
Difficulty 3/5 1-2 days Newbie friendliness 75/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100