def _optimistic_insert(self, primary_name, value, n=<NUM_LIT:5>):
while True:<EOL><INDENT>try:<EOL><INDENT>key = self._generate_random_id(n)<EOL>value[primary_name] = key<EOL>self.insert(primary_name, key, value)<EOL>break<EOL><DEDENT>except KeyExistsException:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return key<EOL>
Attempt to insert with randomly generated key until insert
        is successful.

        :param str primary_name: The name of the primary key.
        :param dict value: The dictionary representation of the record.
        :param n: Number of characters in random key