Fix #502. Fix a race condition in assigning id to db+series+field