-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Do not try to store invalid data in the stats table #8226
Changes from 3 commits
3329c8f
e1cbf94
228b715
8005dbb
a592557
a2ab4c7
94e8a18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixes a longstanding bug where stats updates could break when unexpected profile data was included in events. | ||
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -231,7 +231,8 @@ async def update_room_state(self, room_id: str, fields: Dict[str, Any]) -> None: | |||
""" | ||||
|
||||
# For whatever reason some of the fields may contain null bytes, which | ||||
# postgres isn't a fan of, so we replace those fields with null. | ||||
# postgres isn't a fan of, or be an unexpected type. Replace those | ||||
# fields with null. | ||||
for col in ( | ||||
"join_rules", | ||||
"history_visibility", | ||||
|
@@ -242,7 +243,7 @@ async def update_room_state(self, room_id: str, fields: Dict[str, Any]) -> None: | |||
"canonical_alias", | ||||
): | ||||
field = fields.get(col) | ||||
if field and "\0" in field: | ||||
if not isinstance(field, str) or "\0" in field: | ||||
|
await self.store.update_room_state(room_id, state) |
I must apologise for the lack of docstring which makes it clear, though it also looks like I inherited this function..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was assuming that the dictionary would include strings or None for all fields, but you're 100% correct that this does slightly change the behavior!
In the case of invalid data, does upserting with None
make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code as-is will never "clear" a value (e.g. if topic goes from "foo" -> None it will be stale and stay at "foo" forever). I'm unsure if this is correct behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code as-is will never "clear" a value (e.g. if topic goes from "foo" -> None it will be stale and stay at "foo" forever). I'm unsure if this is correct behavior.
I guess I didn't think too hard about unsetting topics; can you do that, or would it be empty string? (not that empty string was properly handled to begin with, by the looks)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think upserting with None when you get invalid data is fine, if that corresponds with the interpretation that clients, etc are meant to have.
If you get a history_visibility entry with an invalid value, what happens? Stays the same, or resets to some 'default' value? I suppose that is ultimately what might guide us here.
(Though this isn't used for any important information other than the room directory really, so as long as it always leads to a 'safer' outcome I suppose it's fine; e.g. not revealing private rooms in the public room list even if they have sent nonsense visibility and join rule state events)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed some changes which should stop overriding data that wasn't submitted. I also fixed the issue of being unable to submit None
values into the method. I'm not 100% sure that's correct or not though.
Uh oh!
There was an error while loading. Please reload this page.