> Why don't you just do kwargs['metadata'] = metadata?

Fixed.