Skip to content

Commit

Permalink
populate_db: Sort the streams according to their name before creating…
Browse files Browse the repository at this point in the history
… them.

This is required for test fixtures which contain `stream_id`. Prior
to python 3.3 hashes were not randomized but after a security fix
hash randomization was enabled by default in python 3.3 which made
iteration of dictionaries and sets completely unpredictable.
  • Loading branch information
HarshitOnGitHub committed Jul 16, 2017
1 parent d761708 commit 1731da3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zerver/lib/bulk_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def bulk_create_streams(realm, stream_dict):
invite_only=options["invite_only"]
)
)
# Sort streams by name before creating them so that we can have a
# reliable ordering of `stream_id` across different python versions.
# This is required for test fixtures which contain `stream_id`. Prior
# to python 3.3 hashes were not randomized but after a security fix
# hash randomization was enabled in python 3.3 which made iteration
# of dictionaries and sets completely unpredictable. Here the order
# of elements while iterating `stream_dict` will be completely random
# for python 3.3 and later versions.
streams_to_create.sort(key=lambda x: x.name)
Stream.objects.bulk_create(streams_to_create)

recipients_to_create = [] # type: List[Recipient]
Expand Down

0 comments on commit 1731da3

Please sign in to comment.