It does work in a function, but not within a ui action. The reason for this is that ui actions block the main thread of the app by default, which would essentially cause it to hang if it would present a modal dialog or anything like that. The pick_image function detects this, and simply does nothing in this case.

You can fix this by "decorating" your action with @ui.in_background, like this: