Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reseed for each auto id on 3.6 to avoid collisions #388

Merged
merged 6 commits into from Jul 7, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions google/cloud/firestore_v1/base_collection.py
Expand Up @@ -14,6 +14,8 @@

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

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

Expand Down Expand Up @@ -455,6 +457,13 @@ 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 using a
# uuid4 on each iteration to avoid collisions.
seed = str(uuid.uuid4())
random.seed(seed)
tseaver marked this conversation as resolved.
Show resolved Hide resolved

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


Expand Down