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

Commit 4ecf518

Browse files
authored
Include outlier status in str(event) for V2/V3 events (#10879)
I meant to do this before, in #10591, but because I'm stupid I forgot to do it for V2 and V3 events. I've factored the common code out to `EventBase` to save us having two copies of it. This means that for `FrozenEvent` we replace `self.get("event_id", None)` with `self.event_id`, which I think is safe. `get()` is an alias for `self._dict.get()`, whereas `event_id()` is an `@property` method which looks up `self._event_id`, which is populated during construction from the same dict. We don't seem to rely on the fallback, because if the `event_id` key is absent from the dict then construction of the `EventBase` object will fail. Long story short, the only way this could change behaviour is if `event_dict["event_id"]` is changed *after* the `EventBase` object is constructed without updating the `_event_id` field, or vice versa - either of which would be very problematic anyway and the behavior of `str(event)` is the least of our worries.
1 parent a2d7195 commit 4ecf518

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

changelog.d/10879.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include outlier status when we log V2 or V3 events.

synapse/events/__init__.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,18 @@ def freeze(self):
344344
# this will be a no-op if the event dict is already frozen.
345345
self._dict = freeze(self._dict)
346346

347+
def __str__(self):
348+
return self.__repr__()
349+
350+
def __repr__(self):
351+
return "<%s event_id=%r, type=%r, state_key=%r, outlier=%s>" % (
352+
self.__class__.__name__,
353+
self.event_id,
354+
self.get("type", None),
355+
self.get("state_key", None),
356+
self.internal_metadata.is_outlier(),
357+
)
358+
347359

348360
class FrozenEvent(EventBase):
349361
format_version = EventFormatVersions.V1 # All events of this type are V1
@@ -392,17 +404,6 @@ def __init__(
392404
def event_id(self) -> str:
393405
return self._event_id
394406

395-
def __str__(self):
396-
return self.__repr__()
397-
398-
def __repr__(self):
399-
return "<FrozenEvent event_id=%r, type=%r, state_key=%r, outlier=%s>" % (
400-
self.get("event_id", None),
401-
self.get("type", None),
402-
self.get("state_key", None),
403-
self.internal_metadata.is_outlier(),
404-
)
405-
406407

407408
class FrozenEventV2(EventBase):
408409
format_version = EventFormatVersions.V2 # All events of this type are V2
@@ -478,17 +479,6 @@ def auth_event_ids(self):
478479
"""
479480
return self.auth_events
480481

481-
def __str__(self):
482-
return self.__repr__()
483-
484-
def __repr__(self):
485-
return "<%s event_id=%r, type=%r, state_key=%r>" % (
486-
self.__class__.__name__,
487-
self.event_id,
488-
self.get("type", None),
489-
self.get("state_key", None),
490-
)
491-
492482

493483
class FrozenEventV3(FrozenEventV2):
494484
"""FrozenEventV3, which differs from FrozenEventV2 only in the event_id format"""

0 commit comments

Comments
 (0)