Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating from 20 to 21 auto-id chars.
Browse files Browse the repository at this point in the history
This way the entropy is preserved after dropping the alphabet
from 62 to 55 characters:

  >>> (62. / 55.)**20
  10.979435205204474
  >>> 55**20 < 62**20 < 55**21
  True
dhermes committed Dec 4, 2017

Verified

This commit was signed with the committer’s verified signature.
sandhose Quentin Gliech
1 parent 501c5d1 commit 7611a97
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions firestore/google/cloud/firestore_v1beta1/collection.py
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ def document(self, document_id=None):
Args:
document_id (Optional[str]): The document identifier
within the current collection. If not provided, will default
to a random 20 character string composed of digits,
to a random 21 character string composed of digits,
uppercase and lowercase and letters.
Returns:
@@ -138,7 +138,7 @@ def add(self, document_data, document_id=None):
document_id (Optional[str]): The document identifier within the
current collection. If not provided, an ID will be
automatically assigned by the server (the assigned ID will be
a random 20 character string composed of digits,
a random 21 character string composed of digits,
uppercase and lowercase letters).
Returns:
@@ -375,8 +375,8 @@ def _auto_id():
"""Generate a "random" automatically generated ID.
Returns:
str: A 20 character string composed of digits, uppercase and
str: A 21 character string composed of digits, uppercase and
lowercase and letters.
"""
return ''.join(
random.choice(_AUTO_ID_CHARS) for _ in six.moves.xrange(20))
random.choice(_AUTO_ID_CHARS) for _ in six.moves.xrange(21))
4 changes: 2 additions & 2 deletions firestore/tests/unit/test_collection.py
Original file line number Diff line number Diff line change
@@ -427,12 +427,12 @@ def _call_fut():
def test_it(self, mock_rand_choice):
from google.cloud.firestore_v1beta1.collection import _AUTO_ID_CHARS

mock_result = '0123456789abcdefghij'
mock_result = '23456789abcdefghjkmnp'
mock_rand_choice.side_effect = list(mock_result)
result = self._call_fut()
self.assertEqual(result, mock_result)

mock_calls = [mock.call(_AUTO_ID_CHARS)] * 20
mock_calls = [mock.call(_AUTO_ID_CHARS)] * 21
self.assertEqual(mock_rand_choice.mock_calls, mock_calls)


0 comments on commit 7611a97

Please sign in to comment.