Motoko system canister #upgrade without args?

I have been using the following for upgrading my actor classes in motoko
await (system MyActor)(#upgrade(canisterId))(arg1, ag2, arg3)
From what Im guessing, those args1…3 are not acutally used (correct me if im wrong)
The issue is that I have just been faking the args before, but now I am passing in args like shared functions, which im not sure how to fake
Is there a way around this or is there an easier way to call an upgrade without needing to specify paramters?

I ended up creating a dummy shared method on the

public shared query ({ caller }) func fakeCallback() : async ?MyType {
        null;
    };

but its not very sustainable. I dont have access to the real callback

Sorry for the delay.

The args are necessary - on upgrade, the object constructor is run with whatever args are passed to the upgrade.

Whether or not they are used depends on the class itself, of course.

Passing dummy callbacks of the right type as you do should be ok.

Please be careful using this feature - at the moment there are no checks, static nor dynamic, that the upgrade is compatible with the replaced actor.

1 Like

Are there safer ways of upgrading? Or a way you think is best right now?

1 Like

I think for now you just have to be careful and/or verify compatibility offline using didc and moc --stable-compatible (see Verifying upgrade compatibility | Internet Computer, also here Stable variables and upgrade methods | Internet Computer) but doing this for imported actor classes might be awkward since it will be hard to extract the interfaces.

Perhaps if you compile them separately, as standalone classes, it can be done quite easily.

@luc-blaeser has been working on a larger feature which will actually also do a runtime check of compatibility, aborting the upgrade if either the stable variables are incompatible (and possibly the external interface too) but it’s still experimental.

1 Like