@@ -255,6 +255,9 @@ async fn migrate_threepids(
255
255
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
256
256
. to_owned ( ) ;
257
257
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
258
+ if is_likely_appservice ( & username) {
259
+ continue ;
260
+ }
258
261
return Err ( Error :: MissingUserFromDependentTable {
259
262
table : "user_threepids" . to_owned ( ) ,
260
263
user : synapse_user_id,
@@ -332,6 +335,9 @@ async fn migrate_external_ids(
332
335
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
333
336
. to_owned ( ) ;
334
337
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
338
+ if is_likely_appservice ( & username) {
339
+ continue ;
340
+ }
335
341
return Err ( Error :: MissingUserFromDependentTable {
336
342
table : "user_external_ids" . to_owned ( ) ,
337
343
user : synapse_user_id,
@@ -409,6 +415,9 @@ async fn migrate_devices(
409
415
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
410
416
. to_owned ( ) ;
411
417
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
418
+ if is_likely_appservice ( & username) {
419
+ continue ;
420
+ }
412
421
return Err ( Error :: MissingUserFromDependentTable {
413
422
table : "devices" . to_owned ( ) ,
414
423
user : synapse_user_id,
@@ -481,6 +490,9 @@ async fn migrate_unrefreshable_access_tokens(
481
490
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
482
491
. to_owned ( ) ;
483
492
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
493
+ if is_likely_appservice ( & username) {
494
+ continue ;
495
+ }
484
496
return Err ( Error :: MissingUserFromDependentTable {
485
497
table : "access_tokens" . to_owned ( ) ,
486
498
user : synapse_user_id,
@@ -587,6 +599,9 @@ async fn migrate_refreshable_token_pairs(
587
599
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
588
600
. to_owned ( ) ;
589
601
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
602
+ if is_likely_appservice ( & username) {
603
+ continue ;
604
+ }
590
605
return Err ( Error :: MissingUserFromDependentTable {
591
606
table : "refresh_tokens" . to_owned ( ) ,
592
607
user : synapse_user_id,
@@ -685,3 +700,15 @@ fn transform_user(
685
700
686
701
Ok ( ( new_user, mas_password) )
687
702
}
703
+
704
+ /// Returns true if and only if the given localpart looks like it would belong
705
+ /// to an application service user.
706
+ /// The rule here is that it must start with an underscore.
707
+ /// Synapse reserves these by default, but there is no hard rule prohibiting other namespaces
708
+ /// from being reserved, so this is not a robust check.
709
+ // TODO replace with a more robust mechanism, if we even care about this sanity check
710
+ // e.g. read application service registration files.
711
+ #[ inline]
712
+ fn is_likely_appservice ( localpart : & str ) -> bool {
713
+ localpart. starts_with ( '_' )
714
+ }
0 commit comments