Repository: matrix-org/synapse

Issue:
Sqlite Error: Error binding parameter 1 - probably unsupported type (when joining a room)
### Description

Synapse produces an obscure sqlite error when joining a room.

### Steps to reproduce

- Install synapse 1.19.2
- join `#matrix-spec:matrix.org`

Additional anomalous information: I joined `#thisweekinmatrix:matrix.org` and `#conduit:matrix.org` before this, both are subject to current conduit.rs experiments (which led to the security release of 1.19.2)

<details><summary>Additional logs:</summary>

```
synapse_1  | 2020-09-17 15:44:59,053 - synapse.http.server - 84 - ERROR - POST-1715 - Failed handle request via 'JoinRoomAliasServlet': <XForwardedForRequest at 0x7f175a2b9550 method='POST' uri='/_matrix/client/r0/join/%23matrix-spec%3Amatrix.org' clientproto='HTTP/1.1' site=8008>
synapse_1  | Traceback (most recent call last):
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 229, in _async_render_wrapper
synapse_1  |     callback_return = await self._async_render(request)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 406, in _async_render
synapse_1  |     callback_return = await raw_callback_return
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/rest/client/v1/room.py", line 318, in on_POST
synapse_1  |     third_party_signed=content.get("third_party_signed", None),
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/room_member.py", line 317, in update_membership
synapse_1  |     require_consent=require_consent,
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/room_member.py", line 503, in _update_membership
synapse_1  |     requester, remote_room_hosts, room_id, target, content
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/room_member.py", line 1032, in _remote_join
synapse_1  |     remote_room_hosts, room_id, user.to_string(), content
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1360, in do_invite_join
synapse_1  |     origin, auth_chain, state, event, room_version_obj
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2045, in _persist_auth_tree
synapse_1  |     for e in itertools.chain(auth_events, state)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2923, in persist_events_and_notify
synapse_1  |     event_and_contexts, backfilled=backfilled
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/storage/persist_events.py", line 226, in persist_events
synapse_1  |     defer.gatherResults(deferreds, consumeErrors=True)
synapse_1  | twisted.internet.defer.FirstError: FirstError[#0, [Failure instance: Traceback: <class 'sqlite3.InterfaceError'>: Error binding parameter 1 - probably unsupported type.
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:654:_runCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1475:gotResult
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1416:_inlineCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/failure.py:512:throwExceptionIntoGenerator
synapse_1  | --- <exception caught here> ---
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/persist_events.py:148:handle_queue_loop
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/persist_events.py:254:persisting_queue
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/persist_events.py:430:_persist_events
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1416:_inlineCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/failure.py:512:throwExceptionIntoGenerator
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/databases/main/events.py:177:_persist_events_and_state_updates
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1416:_inlineCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/failure.py:512:throwExceptionIntoGenerator
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:527:runInteraction
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1416:_inlineCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/failure.py:512:throwExceptionIntoGenerator
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:575:runWithConnection
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/threadpool.py:250:inContext
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/threadpool.py:266:<lambda>
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/context.py:122:callWithContext
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/context.py:85:callWithContext
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/enterprise/adbapi.py:306:_runWithConnection
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/python/compat.py:464:reraise
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/enterprise/adbapi.py:297:_runWithConnection
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:572:inner_func
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:416:new_transaction
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/logging/utils.py:71:wrapped
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/databases/main/events.py:409:_persist_events_txn
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/databases/main/events.py:947:_update_metadata_tables_txn
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/databases/main/events.py:1116:_store_room_members_txn
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:685:simple_insert_many_txn
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:211:executemany
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/storage/database.py:234:_do_execute
synapse_1  | ]]
```

</details>

### Version information

<!-- IMPORTANT: please answer the following questions, to help us narrow down the problem -->

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**: `jboi.nl`
- **Version**: `1.19.2`
- **Install method**: `docker-compose`, image `docker.io/matrixdotorg/synapse:latest` (effectively `:1.19.2` at time of error)
- **Platform**: Debian 10, Docker CE version `19.03.12`



Discussion:
Does this actually prevent you from joining the room?
Yes
[stuff.txt](https://github.com/matrix-org/synapse/files/5240637/stuff.txt)

Here is some additional logs, this log range starts before i hit `/join #matrix-spec:matrix.org`, and ends after it has returned an error to element.

Note `POST-10781` and the obvious traceback in the middle of the log.
I've ran some more repeats of this, i now got a log which has `synapse.storage.SQL` and `synapse.storage.txn` set to `DEBUG`, after `grep`ping out the relevant HTTP-# and SQL-txn-# into another file, and checking it for any further personally-identifiable information (and redacting that), here is the SQL/TXN log of a similar join attempt:

[synapse.stripped.log](https://github.com/matrix-org/synapse/files/5240796/synapse.stripped.log)

I think the relevant logs are:

```
2020-09-17 16:47:50,643 - synapse.storage.SQL - 221 - DEBUG - persist_events-0 - [SQL] {persist_events-18c} INSERT INTO room_memberships (avatar_url, display_name, event_id, membership, room_id, sender, user_id) VALUES(?, ?, ?, ?, ?, ?, ?)
2020-09-17 16:47:50,643 - synapse.storage.SQL - 226 - DEBUG - persist_events-0 - [SQL values] {persist_events-18c} ((None, None, '$P_4EZJsyghSqOT3nfygCzhjljMEgbGfelsoWoxVmujI', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@josef:netzgemeinde.eu'), (None, 'josef', '$9Vh5DG4LqKmDzQv8iZmvKLynI6arXjHTGo2WNi8rmcg', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@josef:netzgemeinde.eu', '@josef:netzgemeinde.eu'), (None, None, '$kwkuQCD8-4NSXDRmEBQ16EfEpetIFUL137Yidb43LLw', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), (None, None, '$hwKgJFy0B0gY1TMj5e-c6_PSYGUGjaheCHxqV32fecU', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@clokep:matrix.org'), (None, None, '$sddeMlzBtpjxB_q8_jXPWb4PsHUIDpRE-uQP22GbLEY', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@lorico:uraziel.de'), ('mxc://matrix.org/rJYwSVnbzyuzQmKUkpyLzPFX', 'pioneer', '$-UwMaGuMA_jjznEQsBr1fHY4wPzBV3xLmEG-gSQ4VHY', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@pioneer:matrix.org', '@pioneer:matrix.org'), ('', 'pioneer', '$4qD-qxXmgk45r0E4tc37nZgEdXv2XeYoTkdpHKyAD_M', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@pioneer:matrix.org', '@pioneer:matrix.org'), ('mxc://uraziel.de/42565773c6925dcac1e1fac427d78ce9f075e893', 'lorico', '$0QLBLjlbkp-jztcgPS5i_Lz82U2Cf-fcYYL9WeKulOk', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@lorico:uraziel.de', '@lorico:uraziel.de'), (None, 'MichaelRaskin', '$dHIQI5cIR1U3eXk0GOiMFxVhPJkTLEoHl1jK3F_QzSA', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), (None, 'peterblitz', '$WT0k4x9xXuoHExb61LlwfheLLsAqXC_3Bupw3dU04Cs', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@peterblitz:matrix.org', '@peterblitz:matrix.org'), (None, 'ivo-wingelaar', '$wfvVWyK6RzwGbtLpqUfR0gs4yxuAOgzVeaIO6OIUPi8', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@ivo-wingelaar:matrix.org', '@ivo-wingelaar:matrix.org'), (None, 'oscar', '$WooHuP8UFjbaudzWHWhnxoi8NedBqsjsBz7SiOmm2Lo', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@oscar:cybre.space', '@oscar:cybre.space'), (None, None, '$g7lKLb7Fg48W4OgOxYW8_bD9Qs1a8UoHo8ALQdgkNLo', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@florian:dsn.tm.kit.edu'), ('mxc://sorunome.de/ecc3965c24338e0db9f116666419feb44f242851', 'Sorunome', '$IXTuLupKScSuhHeL4qPh6HSbI45wCMhfgXLu5tVbiOc', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@sorunome:sorunome.de', '@sorunome:sorunome.de'), (None, None, '$vYHrpqcq5k0GbGNFnG3qi1ioAQAg2jkAvCYMDIbLwWw', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), ('mxc://matrix.org/dhNtimyMZYPpsdUNCoTBboNv', 'strixaluco', '$RqH2WBInMjjvwedZvSPq0bPRj6ywpSBG6M8-6F62VE4', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@strixaluco:matrix.org', '@strixaluco:matrix.org'), (None, 'MichaelRaskin', '$xM1PmXTX1bkt_o-7_G6PKVxBKKT3exh7obCkrzrvkbw', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), (None, None, '$WKAOGKZYRCo8tiUgAjWR6lO7sqoJnF_Rj9pqUPBY0AM', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), ('mxc://matrix.org/rpPWLtUZptYfdDqCEAcHgBAM', '. Â¦3<RELATIVISM', '$FaSJ0LxSiEE2_6EkvUJqCsiYlrnPCzNeDpC3i_w_fQc', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@alexissampaiokokorelis:matrix.org', '@alexissampaiokokorelis:matrix.org'), (None, '. Â¦3<RELATIVISM', '$UoD_LAKaof-93S6bXsob3mFl3lnvjeOZi1YHSrPhMTk', 'invite', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@sk-alexis:envs.net'), (None, 'MichaelRaskin', '$E_hokci90piEzYHWxCz_-a0-RJhR_tVd3pj_zTaoKZY', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), (None, None, '$rdsP1pN-E6iE8-w96ZyacwCbcRW0cLaLYbXhuLeA3fM', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@freenode_MichaelRaskin:matrix.org', '@freenode_MichaelRaskin:matrix.org'), ('mxc://maunium.net/jdlSfvudiMSmcRrleeiYjjFO', '', '$hitnUIGB3E29mYSUj0GTKLwKW1u_P66xnfUMDY7CjgM', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@tulir:maunium.net', '@tulir:maunium.net'), ('mxc://maunium.net/jdlSfvudiMSmcRrleeiYjjFO', [], '$K3tFdgObmlXu7M4jtnDGdxLFz2AZQN00t1jUTLswupY', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@tulir:maunium.net', '@tulir:maunium.net'), (None, None, '$E_I_81bmanQiTsAGl1Z3OQlA8fg-QVOjhr0rKCKZUZs', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@twilight:twilightsparkle.dev'), (None, None, '$-Ech4I3HYHK5bjz0WvUS5RouLn4KuX3CSi0svaT7gPU', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@lorico:uraziel.de'), ('mxc://matrix.florian-zier.de/xwaISByNkRzrXXtXqjUJTeZf', 'ZierF', '$N_lHganwh4TM_sHAn73eZQKJHh4ixC7cRaZbll0Ch1A', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@zierf:matrix.florian-zier.de', '@zierf:matrix.florian-zier.de'), ('mxc://conduit.rs/5X8noVQpyo70KZ1Cqbn3PuU4ApXC0ZcUn7fpdVNkujeTX5bVSPP9mM3gGFgNk4Qn43bU4DW3PT4mET8MmIHx5ji298sd7LXomd0qqYABwOpbhwCCW7U9Yqj7mhjgx8vZQyZZsZ7bV3E3F4e4m6l0of9tW94nvsAvBvJNFIF8YpsXvefkGFyYueNL5kFDWW8ImgmWIOzHSgxiFUQvL4JdDqqmhmQrI1AMVQFj7OkzidaoKVUSK2l7r0jQL0ADTQ6M', 'Timo[âš¡ï¸]', '$jMR2A8bFoR-JWupTv_QBDU2ULixyGVHktDqUmWRby0o', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@timo:conduit.rs', '@timo:conduit.rs'), ('mxc://jboi.nl/uBbhCspLaCvTBrqpannGpyMk', 'Jonathan', '$TlORNO8ai4vc5uIdQs1IQ0P0ITp7mixM-OA-zPe6uTg', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@jboi:jboi.nl', '@jboi:jboi.nl'), ('mxc://jboi.nl/uBbhCspLaCvTBrqpannGpyMk', 'Jonathan', '$IjzFLoScaWeRVA9lODrAVAMy3-i0yxPuBrQ7ooMww3M', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@jboi:jboi.nl', '@jboi:jboi.nl'), ('mxc://jboi.nl/uBbhCspLaCvTBrqpannGpyMk', 'Jonathan', '$tQW6LdMd6t2urTjQaKy86f6DkL_31ZX2aXW0CwmkbrM', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@jboi:jboi.nl', '@jboi:jboi.nl'), ('mxc://jboi.nl/uBbhCspLaCvTBrqpannGpyMk', 'Jonathan', '$kj08DNfW-mxxaBKwT4WRjNu4k5R4sRk9GgKllm55KtU', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@jboi:jboi.nl', '@jboi:jboi.nl'), (None, None, '$79xqwW6acc9elZVu1LbHJIYUTuHodH47SU3ESM9fsik', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@Baco:matrix.org'), (None, None, '$Jc3KR2fzhT44WZ6DxECUzK1oKlnvhiLjVEDFy4xEsj4', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@CromFr:matrix.org'), ('mxc://matrix.org/yxsuJPABibJanWIdbzZNsZwc', 'Faelar', '$6CEYZLEuBV5R0O2xHaRCsZOSiWxmrn2toM1-RxfDoag', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@Faelar:matrix.org', '@Faelar:matrix.org'), (None, None, '$_NaLkZhi0XN_c2aOKT3DoWSRq0kGHWDX8LhVqhAIYAU', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@Giom:matrix.org'), ('mxc://half-shot.uk/6fc3fb176d5246f1e7cf7d89ad4248b8', 'Half-Shot', '$sGwkRZaXjqds96MUi_BJwdsdwKPq45KXMTcEm4Fz_hY', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@Half-Shot:half-shot.uk', '@Half-Shot:half-shot.uk'), (None, None, '$aoBh2BUxUa2-N6qy5pGcCTmSpbMuZ-FC-KrsLS4vKdc', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@MTRNord:matrix.org'), (None, None, '$A7MErOwkvmTjjreqrs5gqkfGl2q6N55moEovHlKp4JA', 'ban', '!NasysSDfxKxZBzJJoE:matrix.org', '@abuse:matrix.org', '@MilkManzJourDaddy:matrix.org'), (None, None, '$OSK6hyh_g7BQLLSj9xmG8s8FVTQ1DIMtntjb_1EtMpQ', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@TheJJ:matrix.org', '@TheJJ:matrix.org'), (None, None, '$M2wROkrZKv5bcZ10KME381w8F20Nxt4VWNuT181k4Wo', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@TilCreator:matrix.org'), (None, None, '$uqCGu5cBANyYSutvyJiEjezLiks1Y9y-Burn31IUPKc', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@ZLima12:matrix.org'), ('mxc://matrix.org/KfkLMomWWjVZMbgVCKisfFPy', 'Github', '$kKh00jWvpbcmoRlscQTTaWnRoeUbtDt11eBZL7b78kg', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@_neb_github:matrix.org', '@_neb_github:matrix.org'), (None, None, '$EonN9Xom8OXcmTch5iJ-B5D8dAyHYnlpOlh31TlczQA', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@a_v_p:matrix.org'), (None, None, '$K7iut5TKYODdm6un7OUiQO2I_xAPWzOCYXZt718WVqE', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@aaron:axvigs.com'), (None, None, '$qf1XryqH3rITuigr8lBMtN5NecjpBZogWnXbDX_bTMs', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@aaron:hope.net'), ('mxc://kittenface.studio/fClzyKoJrPjBdSsoVYGglwqL', 'Ananace', '$dg0HsTFaTMa-Z1iVkb40dVRRi08IIPHd71MIJmzuxrU', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@ace:kittenface.studio', '@ace:kittenface.studio'), (None, 'Ahmed Charles', '$TILzyrmrYPJxzMyFgXmBgwDANGwIWLu_0lTtYdViUqQ', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@acharles:matrix.org', '@acharles:matrix.org'), (None, None, '$0LWcsnNoEdcXglL-Y2Lf2hlUCHYbHAXpcfGlmY-rUZ0', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@ada:matrix.allmende.io'), (None, None, '$HV4c_rc8u2DV0bQWf3gu4avZA5U8GZjm-MCmoVzPqH4', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@adam:thebeckmeyers.xyz', '@adam:thebeckmeyers.xyz'), (None, None, '$-lGHPrvZr33xQuaW6xtzKKwBqmIpbybQreyfEO1rgEA', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@agorise:matrix.org', '@agorise:matrix.org'), (None, None, '$wUYuHH__unTCJzdhxqWURjc3wGv2yAwmjtenSOATM68', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@airin:matrix.org'), (None, None, '$7VddkstlJ6ADDBzWnIM5vgQwkIaAXQj8KJJuUzQ7MvU', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@alani831:matrix.org', '@alani831:matrix.org'), (None, None, '$pWG5k_oM3ZfaTwrj1T5rtpyDJqB5vtb6EiDXMLLLWwM', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@alexissampaiokokorelis:matrix.org', '@alexissampaiokokorelis:matrix.org'), (None, None, '$gO-Aoj6MBKK8C5l1TYsEZuQ4vmtw19wqKuf9IJt6lZo', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@alfredo:riotchat.de'), (None, None, '$GEZcUMonHqqW15EtD5HDY2yXY96aLYONfG82fGgX_04', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@alphapapa:matrix.org', '@alphapapa:matrix.org'), (None, None, '$ECKSZm-O2Dth2AQHm2A_vJ-JlYgJo27mGQ-LmaUSSHc', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@ananelson:matrix.org'), (None, None, '$V032iQNGwvM_X-_k2FoOtISdipatAuCHGERB5fB8hq0', 'ban', '!NasysSDfxKxZBzJJoE:matrix.org', '@abuse:matrix.org', '@anderson:matrix.heldscal.la'), ('mxc://matrix.org/DcQYnxpVReOKjvwVTvSjwuEO', 'aqtusia', '$pySkc9HSNHdxgky9CtAO0Rkf65aw23CkNKOA0PTL0Vo', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@aqtusia:matrix.org', '@aqtusia:matrix.org'), (None, None, '$krUpSZIvpTHnet6doV5W3EiZvBWrIxJ3vAgKMXyfrwo', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@arne:dramaticexit.de'), (None, None, '$m9grF2eJSYfpaset-CdFcdxby4CS6a781ksehoVHF9g', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@arne:matrix.localtoast.de', '@arne:matrix.localtoast.de'), (None, 'avalenn', '$JLTr0tVUtMQUx2dYmz4_8j1mCr-35i1sIpUbO2AcY3I', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@avalenn:matrix.org', '@avalenn:matrix.org'), (None, 'bch', '$loDY7MKBAFeuFg8v4AX2wwouh8f2qNZtH39uh49ONXM', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@bch:matrix.org', '@bch:matrix.org'), (None, 'Benno FÃ¼nfstÃ¼ck', '$AemlLeO0RiNfnidiw_us9ZTFGz1etUvyeaJ2UGYWJH0', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@bennofs:matrix.org', '@bennofs:matrix.org'), ('mxc://matrix.org/jRqrnjimPBqTSSdJlOupMqSx', 'benoit', '$7vVJ7fZMYbEhbp3vCW9FNR4S_9Szc_8Y6-lkvmZnnXA', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@benoit.marty:matrix.org', '@benoit.marty:matrix.org'), ('mxc://bpulse.org/SJqPkkkvwguFFohqczqtrHdU', 'benpa', '$91wCqklAH0QhsAbfnoce7TUVOOR-efk1_EvEZIhn5Vk', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@benpa:bpulse.org', '@benpa:bpulse.org'), (None, None, '$LZgjMaxoiW5S8FMtmsBKj9-XXrpHPCQ5eRUx3Ss1Xo8', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@benpa:matrix.org', '@benpa:matrix.org'), (None, None, '$Y8z6mLQ6IcB-79m4JdKxC_oG1oYzTigtrAnautY6Gjw', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@bhat:encom.eu.org'), ('mxc://2gather.community/jXOYOkfCMQrDvLVpsYxoZcyA', 'Brendan Miller', '$cBAq9r9Pc6LhMPXQS2GFuX3DSfEY4w4YLgz5su_eAKw', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@bmiller59:2gather.community', '@bmiller59:2gather.community'), (None, None, '$ytGMFFsH6ATUxVK__JbuQU7-lm_kXBReoQcXbdZjTKM', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@bobfett:flobob.ovh', '@bobfett:flobob.ovh'), (None, 'bonvoyage', '$hYHjbahJKafyj5H13tZVSo6T6DQlq4B-r7I7qiULeB4', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@bonvoyage:ungleich.ch', '@bonvoyage:ungleich.ch'), (None, None, '$SIuJ20nY57l2fzhppWYhsf4qEoxDbI2kZtl1QwPu8G4', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@bradjonesca:matrix.org'), (None, None, '$oprw2ozUQfsZjfNP4ZhvU0-v9zkGq1-hAI9ATmkQ3ZQ', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@brendan:abolivier.bzh', '@brendan:abolivier.bzh'), ('mxc://bubu1.eu/lhByohVahvMeDHeJDROhkbXU', 'Bubu', '$UK1iRlXZcc9cjYYrVBg6ICYRMnDVq0H4Piq2_IVsFqo', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@bubu:bubu1.eu', '@bubu:bubu1.eu'), (None, None, '$jB8dgHnLzFqxXIFKytUHMF19NQudawFgs8iv5Wk1wH0', 'leave', '!NasysSDfxKxZBzJJoE:matrix.org', '@appservice-irc:matrix.org', '@bun-bun:matrix.org'), ('mxc://matrix.org/FGdoQWDFRRvhqAkxQFQrmQde', 'BuZZ-dEE', '$VRsMYB3LcEHGrCH62VRe8aQRKTlM4Hcn2-fWrzaNvEw', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@buzz-dee:matrix.org', '@buzz-dee:matrix.org'), ('mxc://matrix.org/aerWVfICBMcyFcEyREcivLuI', 'Bruno', '$bY4yfPxC5BBYxRMN3QcLvDdEmzuTbmynALvjtYsUOpQ', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@bwindels:matrix.org', '@bwindels:matrix.org'), ('mxc://cadair.com/UzelpxcQNpsGDqiEQgOtJcEf', 'Cadair', '$sYRnr94asU0AZisBISKJZJ_e64v9GSOUrKfBHju4rA4', 'join', '!NasysSDfxKxZBzJJoE:matrix.org', '@cadair:cadair.com', '@cadair:cadair.com'), (None, None, '$-ytm6x4UiNbWFNRg_l7tQlWc1yElkmFiCl4yPIqahEE', 'ban', '!NasysSDfxKxZBzJJoE:matrix.org', '@abuse:matrix.org', '@calcatrix:matrix.org'))
2020-09-17 16:47:50,666 - synapse.storage.SQL - 236 - DEBUG - persist_events-0 - [SQL FAIL] {persist_events-18c} Error binding parameter 1 - probably unsupported type.
```
I'm currently digging through the last `SQL Values` statement to spot anything out of the ordinary
Found it, synapse fails on inserting this value:
```py
    (
        "mxc://maunium.net/jdlSfvudiMSmcRrleeiYjjFO",
        [],
        "$K3tFdgObmlXu7M4jtnDGdxLFz2AZQN00t1jUTLswupY",
        "join",
        "!NasysSDfxKxZBzJJoE:matrix.org",
        "@tulir:maunium.net",
        "@tulir:maunium.net",
    )
```
This sounds similar to #8220 then, I'm not sure if upgrading to v1.20.0rc4 would fix it or not though. (I'm unsure how different the code paths are.)
Just to make it a bit easier, the stack trace is:

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 229, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 406, in _async_render
    callback_return = await raw_callback_return
  File "/usr/local/lib/python3.7/site-packages/synapse/rest/client/v1/room.py", line 318, in on_POST
    third_party_signed=content.get("third_party_signed", None),
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/room_member.py", line 317, in update_membership
    require_consent=require_consent,
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/room_member.py", line 503, in _update_membership
    requester, remote_room_hosts, room_id, target, content
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/room_member.py", line 1032, in _remote_join
    remote_room_hosts, room_id, user.to_string(), content
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1360, in do_invite_join
    origin, auth_chain, state, event, room_version_obj
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2045, in _persist_auth_tree
    for e in itertools.chain(auth_events, state)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2923, in persist_events_and_notify
    event_and_contexts, backfilled=backfilled
  File "/usr/local/lib/python3.7/site-packages/synapse/storage/persist_events.py", line 226, in persist_events
    defer.gatherResults(deferreds, consumeErrors=True)
twisted.internet.defer.FirstError: FirstError[#0, [Failure instance: Traceback: <class 'sqlite3.InterfaceError'>: Error binding parameter 1 - probably unsupported type.
```
I just tried this after updating to `v1.20.0rc5`, this is still not fixed @clokep 
> I just tried this after updating to `v1.20.0rc5`, this is still not fixed @clokep

I think in v1.20.0 this might not be fixed for situations where the event comes in over federation, but will be fixed when it comes in over the C-S API.
this is due to a user in the room having set his displayname to `[]` rather than a string (ie, the same cause as #8220). It's certainly a bug in current versions of synapse that it gets upset by this, though it will only be a problem on sqlite. It should be an easy fix.

Resolving patch:
diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py
--- a/synapse/storage/databases/main/events.py
+++ b/synapse/storage/databases/main/events.py
@@ -17,7 +17,7 @@
 import itertools
 import logging
 from collections import OrderedDict, namedtuple
-from typing import TYPE_CHECKING, Dict, Iterable, List, Set, Tuple
+from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple
 
 import attr
 from prometheus_client import Counter
@@ -1108,6 +1108,10 @@ def _store_event_reference_hashes_txn(self, txn, events):
     def _store_room_members_txn(self, txn, events, backfilled):
         """Store a room member in the database.
         """
+
+        def str_or_none(val: Any) -> Optional[str]:
+            return val if isinstance(val, str) else None
+
         self.db_pool.simple_insert_many_txn(
             txn,
             table="room_memberships",
@@ -1118,8 +1122,8 @@ def _store_room_members_txn(self, txn, events, backfilled):
                     "sender": event.user_id,
                     "room_id": event.room_id,
                     "membership": event.membership,
-                    "display_name": event.content.get("displayname", None),
-                    "avatar_url": event.content.get("avatar_url", None),
+                    "display_name": str_or_none(event.content.get("displayname")),
+                    "avatar_url": str_or_none(event.content.get("avatar_url")),
                 }
                 for event in events
             ],


Test patch: