Skip to content

Commit

Permalink
fix: reseed for each auto id on 3.6 to avoid collisions (#388)
Browse files Browse the repository at this point in the history
* fix: Fixes #346 by reseeding for each auto id on py3.6
  • Loading branch information
crwilcox committed Jul 7, 2021
1 parent 13753e2 commit 784e8ae
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions google/cloud/firestore_v1/base_collection.py
Expand Up @@ -14,6 +14,7 @@

"""Classes for representing collections for the Google Cloud Firestore API."""
import random
import sys

from google.api_core import retry as retries # type: ignore

Expand Down Expand Up @@ -455,6 +456,12 @@ def _auto_id() -> str:
str: A 20 character string composed of digits, uppercase and
lowercase and letters.
"""
if sys.version_info < (3, 7):
# TODO: remove when 3.6 support is discontinued.
# On python 3.6, random will provide the same results when forked. Reseed
# on each iteration to avoid collisions.
random.seed()

return "".join(random.choice(_AUTO_ID_CHARS) for _ in range(20))


Expand Down

0 comments on commit 784e8ae

Please sign in to comment.