False positive breaking-change warning in dfx

dfx warns about a breaking change when adding a new tag to an optional variant field.

However, such a change should be considered backwards compatible according to the spec and Roman’s guide.

To make it concrete. Let’s say we have this candid interface:

type Token = variant {
    ICP;
    USDC
};

type Asset = record {
    token : opt Token
};

service : {
    "go" : (Asset) -> (Asset) query
}

If we try to upgrade to a new interface with a new token:

type Token = variant {
    ICP;
    USDC;
    USDT
};

type Asset = record {
    token : opt Token
};

service : {
    "go" : (Asset) -> (Asset) query
}

Then dfx 0.27.0 shows the following warning:

WARNING!
Candid interface compatibility check failed for canister 'check_candid_backend'.
You are making a BREAKING change. Other canisters or frontend clients relying on your canister may stop working.

Method go: func (Asset) -> (Asset) query is not a subtype of func (Asset/1) -> (Asset/1) query
Do you want to proceed? yes/No

I checked that both rust and js can safely handle the change and decode a new token as null (confirmed what the spec says).

2 Likes

Thanks for reporting this, @ulan.

I’ve just opened a PR to fix this behavior:

Although, it won’t be available in dfx until a new Candid release with the proper warning message will be out.

1 Like