@@ -255,6 +255,9 @@ async fn migrate_threepids(
255255 . into_extract_localpart ( synapse_user_id. clone ( ) ) ?
256256 . to_owned ( ) ;
257257 let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
258+ if is_likely_appservice ( & username) {
259+ continue ;
260+ }
258261 return Err ( Error :: MissingUserFromDependentTable {
259262 table : "user_threepids" . to_owned ( ) ,
260263 user : synapse_user_id,
@@ -332,6 +335,9 @@ async fn migrate_external_ids(
332335 . into_extract_localpart ( synapse_user_id. clone ( ) ) ?
333336 . to_owned ( ) ;
334337 let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
338+ if is_likely_appservice ( & username) {
339+ continue ;
340+ }
335341 return Err ( Error :: MissingUserFromDependentTable {
336342 table : "user_external_ids" . to_owned ( ) ,
337343 user : synapse_user_id,
@@ -410,6 +416,9 @@ async fn migrate_devices(
410416 . into_extract_localpart ( synapse_user_id. clone ( ) ) ?
411417 . to_owned ( ) ;
412418 let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
419+ if is_likely_appservice ( & username) {
420+ continue ;
421+ }
413422 return Err ( Error :: MissingUserFromDependentTable {
414423 table : "devices" . to_owned ( ) ,
415424 user : synapse_user_id,
@@ -482,6 +491,9 @@ async fn migrate_unrefreshable_access_tokens(
482491 . into_extract_localpart ( synapse_user_id. clone ( ) ) ?
483492 . to_owned ( ) ;
484493 let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
494+ if is_likely_appservice ( & username) {
495+ continue ;
496+ }
485497 return Err ( Error :: MissingUserFromDependentTable {
486498 table : "access_tokens" . to_owned ( ) ,
487499 user : synapse_user_id,
@@ -589,6 +601,9 @@ async fn migrate_refreshable_token_pairs(
589601 . into_extract_localpart ( synapse_user_id. clone ( ) ) ?
590602 . to_owned ( ) ;
591603 let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
604+ if is_likely_appservice ( & username) {
605+ continue ;
606+ }
592607 return Err ( Error :: MissingUserFromDependentTable {
593608 table : "refresh_tokens" . to_owned ( ) ,
594609 user : synapse_user_id,
@@ -688,3 +703,15 @@ fn transform_user(
688703
689704 Ok ( ( new_user, mas_password) )
690705}
706+
707+ /// Returns true if and only if the given localpart looks like it would belong
708+ /// to an application service user.
709+ /// The rule here is that it must start with an underscore.
710+ /// Synapse reserves these by default, but there is no hard rule prohibiting
711+ /// other namespaces from being reserved, so this is not a robust check.
712+ // TODO replace with a more robust mechanism, if we even care about this sanity check
713+ // e.g. read application service registration files.
714+ #[ inline]
715+ fn is_likely_appservice ( localpart : & str ) -> bool {
716+ localpart. starts_with ( '_' )
717+ }
0 commit comments