Folder::getByID returns nothing when executed in cron.php

Steps to reproduce

  1. Create an own Nextcloud app with a Controller and a registered TimedJob as background job
  2. Create a route (annotated with @NoAdminRequired and @NoCSRFRequired) to execute the logic of the background job manually via HTTP call
  3. Try to get a specific folder by its ID via the “RootStorage” instance of the servers container
  4. Run the background job manually via the defined route and via the cron.php

Expected behaviour

The logic should be executed the same way and the folder with the specific ID should be fetched both times.

Actual behaviour

When executing the background job via cron.php there is no folder returned via the method Folder::getByID. When running the same logic via the defined route, the folder is found.

Server configuration

Operating system: Linux / Docker

Web server: Apache/2.4.38

Database: Embedded SQLite

PHP version: 7.3.18

Nextcloud version: 18.0.5 and 19.0 (see Nextcloud admin page)

Updated from an older Nextcloud/ownCloud or fresh install: both

Where did you install Nextcloud from: Docker hub