Use getter to prevent keyerror. fix #2410