<... stuff ...>
Most importantly check if the item has in_job flag (if so remove from job and unset flag) and don't forget to call dfhack.items.moveToGround so everything is correctly set (e.g. tile flags that it contains item, item list in map chunk etc...)
I tried a more minimal approach, just cleared the item.flags.owned flag, the owned item.general_refs and the unit.owned_items entry, then marked the item for dumping. Eventually the dwarf dropped it. However, that dwarf appears to immediately claim that item (the minecart) as owned any time he picks it up for any reason!
However, the bug is pretty endemic. Several dwarves have claimed ownership of whatever item is in their right hands. I'm trying to create a bug tracker account to document it, but the captcha there appears to be broken.
The item also appears in units.used_items. My doctor was growing attached to a stack of adamantine coins (and who could blame him.) I tried removing the reference to the item from used_items. Let's see if he stops picking it back up now.
Oh, look! The doctor left a job to take a drink, and has again claimed ownership of the item he was using for a previous job. This time I saw it happen start to finish. I'm certain he just picked up the item (a steel coin) and was melting it when he left to get a drink, and now that coin is held in his right hand, and he is its new owner.
Looking over my dwarf population, 3 out of 20 have some inappropriate items in their right hand. One has six glass pots of alcohol in his right hand, and is asleep in bed. (Ha, that sounds about right.)
That bug is definitely confirmed for 42.04, I'll try to get a Mantis account to post it.