Fix edge case where _dynamic_keys stored as None (#387, #401)