Repository: matrix-org/synapse

Issue:
synapse_port_db Python type error on rejection_status_changed
### Description

When running the ``synapse_port_db`` script, I'm getting thrown a type error.

Synapse version: server_version: 1.77.0, python_version: 3.9.2
PostgreSQL version: psql (PostgreSQL) 13.9 (Debian 13.9-0+deb11u1)
OS: Linux debian 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux

Command used: `sudo synapse_port_db --sqlite-database /home/sysadmin/homeserver.db.backup --postgres-config ./homeserver.yaml --curses`

### Steps to reproduce

- Copy homeserver.db to another location
- Shut down Synapse
- Change homeserver.yaml to reflect PostgreSQL config
- Run synapse_port_db script


### Homeserver

Personal Homeserver

### Synapse Version

{"server_version":"1.77.0","python_version":"3.9.2"}

### Installation Method

Other (please mention below)

### Database

SQLite, attempting to port to Postgres 13.9 (Debian). Fresh installation with only a couple of messages.

### Workers

Single process

### Platform

Installed using my install script (https://github.com/ephidrineon/matrix-synapse-easy-install) using Debian packages.

Running on a VPS (1 Core, 1 GB RAM, 25 GB /), Debian 11. Virtualized using KVM

### Configuration

_No response_

### Relevant log output

```shell
port-synapse.log:

2023-02-19 16:46:55,364 - synapse.config.key - 153 - WARNING - This server is configured to use 'matrix.org' as its trusted key server via the
'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
server since it is long-lived, stable and trusted. However, some admins may
wish to use another server for this purpose.

To suppress this warning and continue using 'matrix.org', admins should set
'suppress_key_server_warning' to 'true' in homeserver.yaml.
--------------------------------------------------------------------------------
2023-02-19 16:46:55,369 - synapse.config.key - 169 - WARNING - Config is missing macaroon_secret_key
2023-02-19 16:46:55,440 - synapse.storage.prepare_database - 115 - INFO - ('main', 'state'): Checking existing schema version
2023-02-19 16:46:55,442 - synapse.storage.prepare_database - 119 - INFO - ('main', 'state'): Existing schema is 73 (+22 deltas)
2023-02-19 16:46:55,442 - synapse.storage.databases.main - 286 - INFO - Checking database for consistency with configuration...
2023-02-19 16:46:55,443 - synapse.storage.prepare_database - 411 - INFO - Applying schema deltas for v73
2023-02-19 16:46:55,445 - synapse.storage.prepare_database - 411 - INFO - Applying schema deltas for v74
2023-02-19 16:46:55,445 - synapse.storage.prepare_database - 546 - INFO - Schema now up to date
2023-02-19 16:46:55,450 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for receipts_linearized(stream_id): 615
2023-02-19 16:46:55,451 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for events(stream_ordering): 577
2023-02-19 16:46:55,451 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for events(stream_ordering): -241
2023-02-19 16:46:55,452 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for ex_outlier_stream(event_stream_ordering): -244
2023-02-19 16:46:55,455 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for un_partial_stated_event_stream(stream_id): 9
2023-02-19 16:46:55,458 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for pushers(id): 46
2023-02-19 16:46:55,458 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for deleted_pushers(stream_id): 1
2023-02-19 16:46:55,459 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for push_rules_stream(stream_id): 1
2023-02-19 16:46:55,460 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for push_rules(id): 1
2023-02-19 16:46:55,460 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for push_rules_enable(id): 1
2023-02-19 16:46:55,460 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for room_account_data(stream_id): 372
2023-02-19 16:46:55,460 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for room_tags_revisions(stream_id): 1
2023-02-19 16:46:55,461 - synapse.storage.databases.main.event_push_actions - 1291 - INFO - Searching for stream ordering 1 month ago
2023-02-19 16:46:55,462 - synapse.storage.databases.main.event_push_actions - 1295 - INFO - Found stream ordering 1 month ago: it's 0
2023-02-19 16:46:55,462 - synapse.storage.databases.main.event_push_actions - 1298 - INFO - Searching for stream ordering 1 day ago
2023-02-19 16:46:55,462 - synapse.storage.databases.main.event_push_actions - 1302 - INFO - Found stream ordering 1 day ago: it's 453
2023-02-19 16:46:55,493 - synapse.storage.prepare_database - 115 - INFO - ('main', 'state'): Checking existing schema version
2023-02-19 16:46:55,495 - synapse.storage.prepare_database - 119 - INFO - ('main', 'state'): Existing schema is 74 (+0 deltas)
2023-02-19 16:46:55,495 - synapse.storage.databases.main - 286 - INFO - Checking database for consistency with configuration...
2023-02-19 16:46:55,496 - synapse.storage.prepare_database - 411 - INFO - Applying schema deltas for v74
2023-02-19 16:46:55,497 - synapse.storage.prepare_database - 546 - INFO - Schema now up to date
2023-02-19 16:46:55,524 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for pushers(id): 46
2023-02-19 16:46:55,525 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for deleted_pushers(stream_id): 1
2023-02-19 16:46:55,525 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for push_rules_stream(stream_id): 1
2023-02-19 16:46:55,526 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for push_rules(id): 1
2023-02-19 16:46:55,527 - synapse.storage.util.id_generators - 92 - INFO - Initialising stream generator for push_rules_enable(id): 1
2023-02-19 16:46:55,533 - synapse.storage.databases.main.event_push_actions - 1291 - INFO - Searching for stream ordering 1 month ago
2023-02-19 16:46:55,537 - synapse.storage.databases.main.event_push_actions - 1295 - INFO - Found stream ordering 1 month ago: it's 0
2023-02-19 16:46:55,537 - synapse.storage.databases.main.event_push_actions - 1298 - INFO - Searching for stream ordering 1 day ago
2023-02-19 16:46:55,542 - synapse.storage.databases.main.event_push_actions - 1302 - INFO - Found stream ordering 1 day ago: it's 453
2023-02-19 16:46:55,786 - synapse_port_db - 759 - INFO - Found 146 tables
2023-02-19 16:46:57,463 - synapse_port_db - 381 - INFO - Table e2e_device_keys_json: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,464 - synapse_port_db - 381 - INFO - Table users_in_public_rooms: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,465 - synapse_port_db - 381 - INFO - Table deleted_pushers: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,465 - synapse_port_db - 381 - INFO - Table event_to_state_groups: 697/697 (rows 1-697) already ported
2023-02-19 16:46:57,465 - synapse_port_db - 381 - INFO - Table user_ips: 0/6 (rows 1-0) already ported
2023-02-19 16:46:57,466 - synapse_port_db - 381 - INFO - Table pushers: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,466 - synapse_port_db - 381 - INFO - Table device_federation_outbox: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,466 - synapse_port_db - 381 - INFO - Table application_services_txns: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,467 - synapse_port_db - 381 - INFO - Table room_tags_revisions: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,467 - synapse_port_db - 381 - INFO - Table current_state_events: 0/141 (rows 1-0) already ported
2023-02-19 16:46:57,467 - synapse_port_db - 381 - INFO - Table threepid_guest_access_tokens: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,467 - synapse_port_db - 381 - INFO - Table appservice_room_list: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,467 - synapse_port_db - 381 - INFO - Table user_filters: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,468 - synapse_port_db - 381 - INFO - Table user_daily_visits: 0/13 (rows 1-0) already ported
2023-02-19 16:46:57,469 - synapse_port_db - 381 - INFO - Table event_backward_extremities: 0/4 (rows 1-0) already ported
2023-02-19 16:46:57,470 - synapse_port_db - 381 - INFO - Table room_stats_state: 0/11 (rows 1-0) already ported
2023-02-19 16:46:57,473 - synapse_port_db - 381 - INFO - Table threepid_validation_token: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,473 - synapse_port_db - 381 - INFO - Table blocked_rooms: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,473 - synapse_port_db - 381 - INFO - Table erased_users: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,473 - synapse_port_db - 381 - INFO - Table room_retention: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,474 - synapse_port_db - 381 - INFO - Table sessions: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,474 - synapse_port_db - 381 - INFO - Table e2e_room_keys: 0/22 (rows 1-0) already ported
2023-02-19 16:46:57,474 - synapse_port_db - 381 - INFO - Table device_lists_remote_cache: 0/20 (rows 1-0) already ported
2023-02-19 16:46:57,475 - synapse_port_db - 381 - INFO - Table insertion_events: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,475 - synapse_port_db - 381 - INFO - Table event_auth: 572/572 (rows 1-572) already ported
2023-02-19 16:46:57,476 - synapse_port_db - 381 - INFO - Table event_auth_chain_links: 0/441 (rows 1-0) already ported
2023-02-19 16:46:57,476 - synapse_port_db - 381 - INFO - Table event_push_actions: 0/4 (rows 1-0) already ported
2023-02-19 16:46:57,476 - synapse_port_db - 381 - INFO - Table room_depth: 0/11 (rows 1-0) already ported
2023-02-19 16:46:57,476 - synapse_port_db - 381 - INFO - Table presence_stream: 6/6 (rows 1-77) already ported
2023-02-19 16:46:57,476 - synapse_port_db - 381 - INFO - Table state_groups: 154/154 (rows 1-154) already ported
2023-02-19 16:46:57,477 - synapse_port_db - 381 - INFO - Table e2e_cross_signing_signatures: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,477 - synapse_port_db - 381 - INFO - Table redactions: 1/1 (rows 1-1) already ported
2023-02-19 16:46:57,477 - synapse_port_db - 381 - INFO - Table profiles: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,477 - synapse_port_db - 381 - INFO - Table device_lists_remote_extremeties: 0/6 (rows 1-0) already ported
2023-02-19 16:46:57,477 - synapse_port_db - 381 - INFO - Table room_memberships: 89/89 (rows 1-89) already ported
2023-02-19 16:46:57,478 - synapse_port_db - 381 - INFO - Table local_media_repository_url_cache: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,483 - synapse_port_db - 381 - INFO - Table received_transactions: 1713/1713 (rows 1-1713) already ported
2023-02-19 16:46:57,484 - synapse_port_db - 381 - INFO - Table stream_ordering_to_exterm: 555/555 (rows 1-555) already ported
2023-02-19 16:46:57,484 - synapse_port_db - 381 - INFO - Table user_directory: 0/8 (rows 1-0) already ported
2023-02-19 16:46:57,487 - synapse_port_db - 381 - INFO - Table room_stats_current: 0/11 (rows 1-0) already ported
2023-02-19 16:46:57,487 - synapse_port_db - 381 - INFO - Table refresh_tokens: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,487 - synapse_port_db - 381 - INFO - Table event_json: 765/765 (rows 1-765) already ported
2023-02-19 16:46:57,488 - synapse_port_db - 381 - INFO - Table room_tags: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,488 - synapse_port_db - 381 - INFO - Table user_stats_current: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,488 - synapse_port_db - 381 - INFO - Table worker_locks: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,488 - synapse_port_db - 381 - INFO - Table event_push_summary_stream_ordering: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,488 - synapse_port_db - 381 - INFO - Table remote_media_cache: 10/10 (rows 1-10) already ported
2023-02-19 16:46:57,489 - synapse_port_db - 381 - INFO - Table rejections: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,489 - synapse_port_db - 381 - INFO - Table event_auth_chains: 0/187 (rows 1-0) already ported
2023-02-19 16:46:57,489 - synapse_port_db - 381 - INFO - Table rooms: 11/11 (rows 1-11) already ported
2023-02-19 16:46:57,489 - synapse_port_db - 381 - INFO - Table current_state_delta_stream: 0/163 (rows 1-0) already ported
2023-02-19 16:46:57,490 - synapse_port_db - 381 - INFO - Table state_groups_state: 294/294 (rows 1-294) already ported
2023-02-19 16:46:57,490 - synapse_port_db - 381 - INFO - Table users: 1/1 (rows 1-1) already ported
2023-02-19 16:46:57,494 - synapse_port_db - 381 - INFO - Table device_lists_stream: 0/43 (rows 1-0) already ported
2023-02-19 16:46:57,494 - synapse_port_db - 381 - INFO - Table open_id_tokens: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,494 - synapse_port_db - 381 - INFO - Table events: 765/765 (rows -241-577) already ported
2023-02-19 16:46:57,495 - synapse_port_db - 381 - INFO - Table stats_incremental_position: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,495 - synapse_port_db - 381 - INFO - Table remote_media_cache_thumbnails: 48/48 (rows 1-48) already ported
2023-02-19 16:46:57,495 - synapse_port_db - 381 - INFO - Table federation_stream_position: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,495 - synapse_port_db - 381 - INFO - Table device_inbox: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,495 - synapse_port_db - 381 - INFO - Table user_directory_search: 0/8 (rows 1-0) already ported
2023-02-19 16:46:57,495 - synapse_port_db - 381 - INFO - Table applied_module_schemas: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,496 - synapse_port_db - 381 - INFO - Table event_relations: 0/4 (rows 1-0) already ported
2023-02-19 16:46:57,496 - synapse_port_db - 381 - INFO - Table event_auth_chain_to_calculate: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,496 - synapse_port_db - 381 - INFO - Table device_lists_changes_in_room: 0/249 (rows 1-0) already ported
2023-02-19 16:46:57,496 - synapse_port_db - 381 - INFO - Table device_lists_remote_pending: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,496 - synapse_port_db - 381 - INFO - Table server_keys_json: 0/5 (rows 1-0) already ported
2023-02-19 16:46:57,496 - synapse_port_db - 381 - INFO - Table receipts_graph: 0/34 (rows 1-0) already ported
2023-02-19 16:46:57,498 - synapse_port_db - 381 - INFO - Table appservice_stream_position: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,505 - synapse_port_db - 381 - INFO - Table local_media_repository_thumbnails: 5/5 (rows 1-5) already ported
2023-02-19 16:46:57,505 - synapse_port_db - 381 - INFO - Table state_group_edges: 130/130 (rows 1-130) already ported
2023-02-19 16:46:57,505 - synapse_port_db - 381 - INFO - Table room_stats_earliest_token: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,505 - synapse_port_db - 381 - INFO - Table user_threepid_id_server: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,505 - synapse_port_db - 381 - INFO - Table application_services_state: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,505 - synapse_port_db - 381 - INFO - Table event_search: 96/96 (rows 1-96) already ported
2023-02-19 16:46:57,506 - synapse_port_db - 381 - INFO - Table event_push_actions_staging: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,506 - synapse_port_db - 381 - INFO - Table monthly_active_users: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,506 - synapse_port_db - 381 - INFO - Table state_events: 187/187 (rows 1-187) already ported
2023-02-19 16:46:57,506 - synapse_port_db - 381 - INFO - Table push_rules: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,507 - synapse_port_db - 381 - INFO - Table insertion_event_extremities: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,507 - synapse_port_db - 381 - INFO - Table ignored_users: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,507 - synapse_port_db - 381 - INFO - Table device_lists_outbound_pokes: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,507 - synapse_port_db - 381 - INFO - Table ratelimit_override: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,507 - synapse_port_db - 381 - INFO - Table event_push_summary: 0/6 (rows 1-0) already ported
2023-02-19 16:46:57,508 - synapse_port_db - 381 - INFO - Table server_signature_keys: 0/5 (rows 1-0) already ported
2023-02-19 16:46:57,508 - synapse_port_db - 381 - INFO - Table users_who_share_private_rooms: 0/41 (rows 1-0) already ported
2023-02-19 16:46:57,508 - synapse_port_db - 381 - INFO - Table event_labels: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,509 - synapse_port_db - 381 - INFO - Table destinations: 0/4 (rows 1-0) already ported
2023-02-19 16:46:57,509 - synapse_port_db - 381 - INFO - Table e2e_one_time_keys_json: 0/100 (rows 1-0) already ported
2023-02-19 16:46:57,509 - synapse_port_db - 381 - INFO - Table e2e_cross_signing_keys: 0/18 (rows 1-0) already ported
2023-02-19 16:46:57,509 - synapse_port_db - 381 - INFO - Table e2e_room_keys_versions: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,510 - synapse_port_db - 381 - INFO - Table event_push_summary_last_receipt_stream_id: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,510 - synapse_port_db - 381 - INFO - Table insertion_event_edges: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,514 - synapse_port_db - 381 - INFO - Table schema_compat_version: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,514 - synapse_port_db - 381 - INFO - Table event_reports: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,514 - synapse_port_db - 381 - INFO - Table account_data: 0/13 (rows 1-0) already ported
2023-02-19 16:46:57,514 - synapse_port_db - 381 - INFO - Table e2e_fallback_keys_json: 0/2 (rows 1-0) already ported
2023-02-19 16:46:57,514 - synapse_port_db - 381 - INFO - Table device_federation_inbox: 0/22 (rows 1-0) already ported
2023-02-19 16:46:57,515 - synapse_port_db - 381 - INFO - Table threepid_validation_session: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,515 - synapse_port_db - 381 - INFO - Table device_lists_changes_converted_stream_position: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,515 - synapse_port_db - 381 - INFO - Table device_auth_providers: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,515 - synapse_port_db - 381 - INFO - Table user_external_ids: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,515 - synapse_port_db - 381 - INFO - Table push_rules_enable: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,515 - synapse_port_db - 381 - INFO - Table ex_outlier_stream: 46/46 (rows 1-46) already ported
2023-02-19 16:46:57,516 - synapse_port_db - 381 - INFO - Table account_validity: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,516 - synapse_port_db - 381 - INFO - Table ui_auth_sessions: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,516 - synapse_port_db - 381 - INFO - Table user_directory_stream_pos: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,516 - synapse_port_db - 381 - INFO - Table receipts_linearized: 0/34 (rows 1-0) already ported
2023-02-19 16:46:57,521 - synapse_port_db - 381 - INFO - Table batch_events: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,521 - synapse_port_db - 381 - INFO - Table threads: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,521 - synapse_port_db - 381 - INFO - Table room_account_data: 0/7 (rows 1-0) already ported
2023-02-19 16:46:57,521 - synapse_port_db - 381 - INFO - Table room_aliases: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,521 - synapse_port_db - 381 - INFO - Table event_expiry: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table users_pending_deactivation: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table push_rules_stream: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table event_forward_extremities: 0/11 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table dehydrated_devices: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table stream_positions: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table registration_tokens: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table user_signature_stream: 0/1 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table device_lists_remote_resync: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table login_tokens: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,522 - synapse_port_db - 381 - INFO - Table background_updates: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table device_lists_outbound_last_success: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table pusher_throttle: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table room_alias_servers: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table local_current_membership: 0/11 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table devices: 0/5 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table federation_inbound_events_staging: 0/0 (rows 1-0) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table local_media_repository: 31/31 (rows 1-31) already ported
2023-02-19 16:46:57,523 - synapse_port_db - 381 - INFO - Table user_threepids: 0/0 (rows 1-0) already ported
2023-02-19 16:46:58,022 - synapse_port_db - 381 - INFO - Table destination_rooms: 0/9 (rows 1-0) already ported
2023-02-19 16:46:58,022 - synapse_port_db - 381 - INFO - Table un_partial_stated_event_stream: 0/8 (rows 1-0) already ported
2023-02-19 16:46:58,022 - synapse_port_db - 381 - INFO - Table ui_auth_sessions_ips: 0/0 (rows 1-0) already ported
2023-02-19 16:46:58,023 - synapse_port_db - 381 - INFO - Table event_failed_pull_attempts: 0/0 (rows 1-0) already ported
2023-02-19 16:46:58,023 - synapse_port_db - 381 - INFO - Table ui_auth_sessions_credentials: 0/0 (rows 1-0) already ported
2023-02-19 16:46:58,023 - synapse_port_db - 381 - INFO - Table event_edges: 757/757 (rows 1-757) already ported
2023-02-19 16:46:58,023 - synapse_port_db - 381 - INFO - Table un_partial_stated_room_stream: 0/8 (rows 1-0) already ported
2023-02-19 16:46:58,023 - synapse_port_db - 381 - INFO - Table access_tokens: 0/2 (rows 1-0) already ported
2023-02-19 16:46:58,023 - synapse_port_db - 381 - INFO - Table users_to_send_full_presence_to: 0/0 (rows 1-0) already ported
2023-02-19 16:46:58,024 - synapse_port_db - 381 - INFO - Table partial_state_rooms: 0/0 (rows 1-0) already ported
2023-02-19 16:46:58,032 - synapse_port_db - 235 - ERROR - Failed to insert: un_partial_stated_event_stream
Traceback (most recent call last):
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:1792:gotResult
--- <exception caught here> ---
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:1693:_inlineCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/failure.py:518:throwExceptionIntoGenerator
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py:482:handle_table
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:882:runInteraction
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:1693:_inlineCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/failure.py:518:throwExceptionIntoGenerator
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:849:_runInteraction
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:977:runWithConnection
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/threadpool.py:244:inContext
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/threadpool.py:260:<lambda>
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/context.py:117:callWithContext
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/context.py:82:callWithContext
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/enterprise/adbapi.py:282:_runWithConnection
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:970:inner_func
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:711:new_transaction
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py:470:insert
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py:233:insert_many_txn
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:391:executemany
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:436:_do_execute

Console output of synapse_port_db:

Traceback (most recent call last):
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py", line 796, in run
    await make_deferred_yieldable(
twisted.internet.defer.FirstError: FirstError[#1, [Failure instance: Traceback: <class 'psycopg2.errors.DatatypeMismatch'>: column "rejection_status_changed" is of type boolean but expression is of type integer
LINE 1: ...'master', '$foQmi7puBLD3_yv4WJKfHnpgi8QApuT8O51mXoKRwqg', 0)
                                                                     ^
HINT:  You will need to rewrite or cast the expression.

/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:735:errback
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:798:_startRunCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:892:_runCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:1792:gotResult
--- <exception caught here> ---
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:1693:_inlineCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/failure.py:518:throwExceptionIntoGenerator
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py:482:handle_table
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:882:runInteraction
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:1693:_inlineCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/failure.py:518:throwExceptionIntoGenerator
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:849:_runInteraction
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:977:runWithConnection
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/threadpool.py:244:inContext
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/threadpool.py:260:<lambda>
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/context.py:117:callWithContext
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/context.py:82:callWithContext
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/enterprise/adbapi.py:282:_runWithConnection
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:970:inner_func
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:711:new_transaction
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py:470:insert
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/_scripts/synapse_port_db.py:233:insert_many_txn
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:391:executemany
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py:436:_do_execute
]]
FirstError[#1, [Failure instance: Traceback: <class 'psycopg2.errors.DatatypeMismatch'>: column "rejection_status_changed" is of type boolean but expression is of type integer
LINE 1: ...'master', '$foQmi7puBLD3_yv4WJKfHnpgi8QApuT8O51mXoKRwqg', 0)
                                                                     ^
HINT:  You will need to rewrite or cast the expression.

/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:735:errback
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:798:_startRunCallbacks
/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py:892:_runCallbacks
```


### Anything else that would be useful to know?

_No response_


Discussion:
We added a boolean column in #14545 https://github.com/matrix-org/synapse/blob/fb60cb16fe3cf26fbd947eec926cb4b24b8e9fc7/synapse/storage/schema/main/delta/73/22_un_partial_stated_event_stream.sql#L17-L30

But didn't mark it as a boolean here:

https://github.com/matrix-org/synapse/blob/65d03866936adb144631d263a8539a2cb060fd43/synapse/_scripts/synapse_port_db.py#L96-L117

Resolving patch:
diff --git a/synapse/_scripts/synapse_port_db.py b/synapse/_scripts/synapse_port_db.py
--- a/synapse/_scripts/synapse_port_db.py
+++ b/synapse/_scripts/synapse_port_db.py
@@ -94,61 +94,80 @@
 logger = logging.getLogger("synapse_port_db")
 
 
+# SQLite doesn't have a dedicated boolean type (it stores True/False as 1/0). This means
+# portdb will read sqlite bools as integers, then try to insert them into postgres
+# boolean columns---which fails. Lacking some Python-parseable metaschema, we must
+# specify which integer columns should be inserted as booleans into postgres.
 BOOLEAN_COLUMNS = {
-    "events": ["processed", "outlier", "contains_url"],
-    "rooms": ["is_public", "has_auth_chain_index"],
+    "access_tokens": ["used"],
+    "account_validity": ["email_sent"],
+    "device_lists_changes_in_room": ["converted_to_destinations"],
+    "device_lists_outbound_pokes": ["sent"],
+    "devices": ["hidden"],
+    "e2e_fallback_keys_json": ["used"],
+    "e2e_room_keys": ["is_verified"],
     "event_edges": ["is_state"],
+    "events": ["processed", "outlier", "contains_url"],
+    "local_media_repository": ["safe_from_quarantine"],
     "presence_list": ["accepted"],
     "presence_stream": ["currently_active"],
     "public_room_list_stream": ["visibility"],
-    "devices": ["hidden"],
-    "device_lists_outbound_pokes": ["sent"],
-    "users_who_share_rooms": ["share_private"],
-    "e2e_room_keys": ["is_verified"],
-    "account_validity": ["email_sent"],
+    "pushers": ["enabled"],
     "redactions": ["have_censored"],
     "room_stats_state": ["is_federatable"],
-    "local_media_repository": ["safe_from_quarantine"],
+    "rooms": ["is_public", "has_auth_chain_index"],
     "users": ["shadow_banned", "approved"],
-    "e2e_fallback_keys_json": ["used"],
-    "access_tokens": ["used"],
-    "device_lists_changes_in_room": ["converted_to_destinations"],
-    "pushers": ["enabled"],
+    "un_partial_stated_event_stream": ["rejection_status_changed"],
+    "users_who_share_rooms": ["share_private"],
 }
 
 
+# These tables are never deleted from in normal operation [*], so we can resume porting
+# over rows from a previous attempt rather than starting from scratch.
+#
+# [*]: We do delete from many of these tables when purging a room, and
+#      presumably when purging old events. So we might e.g.
+#
+#      1. Run portdb and port half of some table.
+#      2. Stop portdb.
+#      3. Purge something, deleting some of the rows we've ported over.
+#      4. Restart portdb. The rows deleted from sqlite are still present in postgres.
+#
+#      But this isn't the end of the world: we should be able to repeat the purge
+#      on the postgres DB when porting completes.
 APPEND_ONLY_TABLES = [
+    "cache_invalidation_stream_by_instance",
+    "event_auth",
+    "event_edges",
+    "event_json",
     "event_reference_hashes",
+    "event_search",
+    "event_to_state_groups",
     "events",
-    "event_json",
-    "state_events",
-    "room_memberships",
-    "topics",
-    "room_names",
-    "rooms",
+    "ex_outlier_stream",
     "local_media_repository",
     "local_media_repository_thumbnails",
+    "presence_stream",
+    "public_room_list_stream",
+    "push_rules_stream",
+    "received_transactions",
+    "redactions",
+    "rejections",
     "remote_media_cache",
     "remote_media_cache_thumbnails",
-    "redactions",
-    "event_edges",
-    "event_auth",
-    "received_transactions",
+    "room_memberships",
+    "room_names",
+    "rooms",
     "sent_transactions",
-    "transaction_id_to_pdu",
-    "users",
+    "state_events",
+    "state_group_edges",
     "state_groups",
     "state_groups_state",
-    "event_to_state_groups",
-    "rejections",
-    "event_search",
-    "presence_stream",
-    "push_rules_stream",
-    "ex_outlier_stream",
-    "cache_invalidation_stream_by_instance",
-    "public_room_list_stream",
-    "state_group_edges",
     "stream_ordering_to_exterm",
+    "topics",
+    "transaction_id_to_pdu",
+    "un_partial_stated_event_stream",
+    "users",
 ]
 
 


Test patch: