Occ sharing:delete-orphan-shares: Backends provided no user object

Nextcloud version (eg, 20.0.5): 27.1.4.
Operating system and version (eg, Ubuntu 20.04): official docker image
Apache or nginx version (eg, Apache 2.4.25): docker
PHP version (eg, 7.4): docker, presume 8.x
User Management: local database

The issue you are facing:

We are having issues with shares.
Some cannot be deleted.
I thought I use occ sharing:delete-orphan-shares -f to clean up.
But it returns:

In Root.php line 364:
                                    
  Backends provided no user object  

I find this error in the log (see below).
The user that the log reports does exist.
In fact, for all shares in oc_share there is an entry in oc_users

Is this the first time you’ve seen this error? N

Steps to replicate it:

  1. execute above command

The output of your Nextcloud log in Admin > Logging:
I have replaced the username by [USERNAME] below

[files] Fehler: OC\User\NoUserException: Backends provided no user object at <<closure>>

 0. <<closure>>
    OC\Files\Node\Root->getUserFolder("[USERNAME]")
 1. /var/www/html/lib/private/Files/Node/LazyFolder.php line 74
    call_user_func_array([["OC\\Files\\No ... "], ["[USERNAME]"])
 2. /var/www/html/lib/private/Files/Node/LazyRoot.php line 40
    OC\Files\Node\LazyFolder->__call("getUserFolder", ["[USERNAME]"])
 3. /var/www/html/apps/files_sharing/lib/OrphanHelper.php line 43
    OC\Files\Node\LazyRoot->getUserFolder("[USERNAME]")
 4. /var/www/html/apps/files_sharing/lib/Command/DeleteOrphanShares.php line 61
    OCA\Files_Sharing\OrphanHelper->isShareValid("[USERNAME]", 19225)
 5. /var/www/html/3rdparty/symfony/console/Command/Command.php line 298
    OCA\Files_Sharing\Command\DeleteOrphanShares->execute(["Symfony\\Compo ... "], ["Symfony\\Compo ... "])
 6. /var/www/html/core/Command/Base.php line 177
    Symfony\Component\Console\Command\Command->run(["Symfony\\Compo ... "], ["Symfony\\Compo ... "])
 7. /var/www/html/3rdparty/symfony/console/Application.php line 1040
    OC\Core\Command\Base->run(["Symfony\\Compo ... "], ["Symfony\\Compo ... "])
 8. /var/www/html/3rdparty/symfony/console/Application.php line 301
    Symfony\Component\Console\Application->doRunCommand(["OCA\\Files_Sha ... "], ["Symfony\\Compo ... "], ["Symfony\\Compo ... "])
 9. /var/www/html/3rdparty/symfony/console/Application.php line 171
    Symfony\Component\Console\Application->doRun(["Symfony\\Compo ... "], ["Symfony\\Compo ... "])
10. /var/www/html/lib/private/Console/Application.php line 211
    Symfony\Component\Console\Application->run(["Symfony\\Compo ... "], ["Symfony\\Compo ... "])
11. /var/www/html/console.php line 100
    OC\Console\Application->run()
12. /var/www/html/occ line 11
    require_once("/var/www/html/console.php")

at 2023-12-10T19:14:35+00:00

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'nextcloud-redis',
    'password' => 'So0iHiXaiHoofeeL',
    'port' => 6379,
  ),
  'overwritehost' => 'xxx',
  'overwriteprotocol' => 'https',
  'overwrite.cli.url' => 'https://xxx',
  'trusted_proxies' => 
  array (
    0 => '172.21.0.2/16',
  ),
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'xxxx',
  'trusted_domains' => 
  array (
    0 => 'xxx',
    1 => 'xxx',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '27.1.4.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'nextcloud-db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxx',
  'installed' => true,
  'default_language' => 'de',
  'default_phone_region' => 'de',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_smtphost' => 'xxx',
  'mail_from_address' => 'cloud',
 'mail_domain' => 'xxx',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtpport' => '587',
  'mail_smtpname' => 'xxx',
  'mail_smtppassword' => 'xxxxxx',
  'simpleSignUpLink.shown' => false,
  'trashbin_retention_obligation' => 'auto, 10',
  'maintenance' => false,
  'loglevel' => 2,
  'app_install_overwrite' => 
  array (
    0 => 'piwik',
  ),
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\MP3',
    1 => 'OC\\Preview\\TXT',
    2 => 'OC\\Preview\\MarkDown',
    3 => 'OC\\Preview\\OpenDocument',
    4 => 'OC\\Preview\\Krita',
    5 => 'OC\\Preview\\Imaginary',
  ),
  'preview_imaginary_url' => 'http://nextcloud-imaginary:9000',
  'skeletondirectory' => '/var/skeleton',

In the logs, I find many entries like the above.
They always point to two different accounts that indeed do not exist.
I find entries in oc_filecache pointing at this user; and I see that folders for the two users exist in the data folder, indicating that they may have existed, but were later deleted.

Is there a method to sync files users, and oc_filecache?
I already tried all the occ options that sounded like clean-up and re-indexing…

./occ files:cleanup 
./occ files:repair-tree
./occ files:scan --all

I deleted the directory from the datafolder, and eliminated them from oc_storages (deleting all “home::” storages that are not linked to an existing user):

DELETE oc_storages FROM oc_storages 
 LEFT OUTER JOIN oc_users  ON (oc_users.uid=substring(oc_storages.id, 7))
WHERE oc_storages.id LIKE 'home::%'
 AND oc_users.uid is null;

Then I re-ran ./occ files:scan --all and then occ sharing:delete-orphan-shares:
I still get the same error message and log entry…