-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix get_filtered_current_state_ids()'s usage of filtered_types #3792
Conversation
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.
lgtm I guess. I'm concerned that there isn't a unit test that picked this up though, particularly given we've made a mess of very similar bits of code elsewhere in the past and it's got all the way out to release before we've noticed - any chance of adding one?
) | ||
) | ||
sql += " AND type <> ? " * len(unique_types) | ||
additional_args = list(unique_types) |
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.
it's not obvious to me that this needs copying: why not just additional_args = unique_types
?
I'm not really sure I'm following what the query looks like here. Say we call this with: store.get_filtered_current_state_ids(
room_id="!foo:bar.com",
types=[("m.room.members", "@bob:foo.com"), ("m.room.topic", "")],
filtered_types=["m.room.members"]
) Would produce two queries: SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = '!foo:bar.com'
AND type = 'm.room.member' AND state_key = '@bob:foo.com' AND type != 'm.room.member' SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = '!foo:bar.com'
AND type = 'm.room.topic' AND state_key = '' AND type != 'm.room.member' Which don't make sense? I feel like I'm missing something? |
Erik makes an excellent point. It doesn't make sense. The docstring on the function is a bit terse; to quote the longer one from some other places:
That makes it much clearer what filtered_types is supposed to do. To take Erik's example, the queries we actually want are therefore: SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = '!foo:bar.com'
AND type = 'm.room.member' AND state_key = '@bob:foo.com';
SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = '!foo:bar.com'
AND type = 'm.room.topic' AND state_key = '';
SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = '!foo:bar.com'
AND type != 'm.room.member'; (it doesn't really make much sense to specify Anyway, I think the above is what the code does currently. In short, wtf, @ara4n ? [not for the first time, the |
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.
this looks wrong, as per the above
@erikjohnston am I right in thinking that your rewrite of the filtered_types hell renders this irrelevant? |
From my reading, it appears so. |
We weren't applying the "AND type<>?" sql clause to every query, as the query was split up into separate ones.
In practice this didn't break anything as nothing currently uses
filtered_types
inget_filtered_current_state_ids
; i just spotted it as a thinko.