This fixes the problem mentioned in 8e1aa5b11c. Turns out that it's a long-standing Synapse bug: https://github.com/matrix-org/synapse/issues/9768
8e1aa5b11c