Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit 784e8ae

Browse files
authored
fix: reseed for each auto id on 3.6 to avoid collisions (#388)
* fix: Fixes #346 by reseeding for each auto id on py3.6
1 parent 13753e2 commit 784e8ae

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

google/cloud/firestore_v1/base_collection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Classes for representing collections for the Google Cloud Firestore API."""
1616
import random
17+
import sys
1718

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

@@ -455,6 +456,12 @@ def _auto_id() -> str:
455456
str: A 20 character string composed of digits, uppercase and
456457
lowercase and letters.
457458
"""
459+
if sys.version_info < (3, 7):
460+
# TODO: remove when 3.6 support is discontinued.
461+
# On python 3.6, random will provide the same results when forked. Reseed
462+
# on each iteration to avoid collisions.
463+
random.seed()
464+
458465
return "".join(random.choice(_AUTO_ID_CHARS) for _ in range(20))
459466

460467

0 commit comments

Comments
 (0)