Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Disable frozen dicts by default #3987

Merged
merged 9 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3987.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable USE_FROZEN_DICTS for unittests by default.
13 changes: 10 additions & 3 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from distutils.util import strtobool

import six

from synapse.util.caches import intern_dict
from synapse.util.frozenutils import freeze

# Whether we should use frozen_dict in FrozenEvent. Using frozen_dicts prevents
# bugs where we accidentally share e.g. signature dicts. However, converting
# a dict to frozen_dicts is expensive.
USE_FROZEN_DICTS = True
# bugs where we accidentally share e.g. signature dicts. However, converting a
# dict to frozen_dicts is expensive.
#
# NOTE: This is overridden by the configuration by the Synapse worker apps, but
# for the sake of tests, it is set here while it cannot be configured on the
# homeserver object itself.
USE_FROZEN_DICTS = strtobool(os.environ.get("SYNAPSE_USE_FROZEN_DICTS", "0"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an intention to set this for the tests somewhere?



class _EventInternalMetadata(object):
Expand Down
6 changes: 5 additions & 1 deletion tests/replication/slave/storage/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from canonicaljson import encode_canonical_json

from synapse.events import FrozenEvent, _EventInternalMetadata
from synapse.events.snapshot import EventContext
from synapse.replication.slave.storage.events import SlavedEventStore
Expand All @@ -26,7 +28,9 @@


def dict_equals(self, other):
return self.__dict__ == other.__dict__
me = encode_canonical_json(self._event_dict)
hawkowl marked this conversation as resolved.
Show resolved Hide resolved
them = encode_canonical_json(other._event_dict)
return me == them


def patch__eq__(cls):
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def default_config(name):
config.rc_messages_per_second = 10000
config.rc_message_burst_count = 10000

config.use_frozen_dicts = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is actually used (since afaict use_frozen_dicts is only read by code which is never run under the UTs), and if not I would probably choose to omit this. But I'm not that bothered and this needs merging.


# we need a sane default_room_version, otherwise attempts to create rooms will
# fail.
config.default_room_version = "1"
Expand Down Expand Up @@ -182,7 +184,6 @@ def setup_test_homeserver(
if config is None:
config = default_config(name)

config.use_frozen_dicts = True
config.ldap_enabled = False

if "clock" not in kargs:
Expand Down