UserDeleteHook constructs Application directly: 'not setup via query()' error on every user deletion with debug on
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start in lib/Hooks/UserDeleteHook.php around line 36, where new Application() is built, and compare it with how lib/AppInfo/Application.php registers the listener. Switching to constructor-injected services means the hook should no longer call new Application(). Done when occ user:delete with 'debug' => true logs no ERROR entry and the user's items, feeds and folders are still removed in the same order.
Written by the indexing model from the issue text.
Description
IMPORTANT
- I have read the CONTRIBUTING.md and followed the provided tips
- I accept that the issue will be closed without comment if I do not check here
- I accept that the issue will be closed without comment if I do not fill out all items in the issue template.
Explain the Problem
With 'debug' => true, deleting a user makes News log a level-3 (ERROR) entry:
RuntimeException: App class OCA\News\AppInfo\Application is not setup via query() but directly
The entry comes from OCP\AppFramework\App::__construct(). When debug is on, it logs an Application that was constructed with new and not resolved through the container. OCA\News\Hooks\UserDeleteHook::handle() does exactly that:
// lib/Hooks/UserDeleteHook.php:36
$app = new Application();
$container = $app->getContainer();
The error is only logged, not thrown. The listener carries on, and the user's items, feeds and folders are still deleted. So the effect is log noise, but every user deletion on a debug instance produces an ERROR entry with a stack trace, and that hides real errors in log checks.
The same code is still on master (the file was last changed in 2020).
Steps to Reproduce
- Set
'debug' => trueinconfig/config.php. - Run
occ user:add --password-from-env newsrepro, thenocc user:delete newsrepro. grep 'not setup via query' data/nextcloud.logshows the entry below.
System Information
- News app version: 29.0.0
- Nextcloud version: 35.0.2
- Cron type: system cron (docker
nextcloud-croncontainer) - PHP version: 8.5.12
- Database and version: PostgreSQL 18.4
- Browser and version: n/a (server-side, reproduced with
occ) - OS and version: official
nextcloud:35-apachedocker image
Contents of nextcloud/data/nextcloud.log
level: 3, app: news, version: 35.0.2.2, occ_command: ["occ","user:delete","newsrepro"]
RuntimeException: App class OCA\News\AppInfo\Application is not setup via query() but directly
custom_apps/news/lib/AppInfo/Application.php:81 OCP\AppFramework\App->__construct
custom_apps/news/lib/Hooks/UserDeleteHook.php:36 OCA\News\AppInfo\Application->__construct
lib/private/EventDispatcher/ServiceEventListener.php:57 OCA\News\Hooks\UserDeleteHook->handle
3rdparty/symfony/event-dispatcher/EventDispatcher.php:206
3rdparty/symfony/event-dispatcher/EventDispatcher.php:56
lib/private/EventDispatcher/EventDispatcher.php:74
lib/private/EventDispatcher/EventDispatcher.php:87
lib/private/User/User.php:266 OC\EventDispatcher\EventDispatcher->dispatchTyped
core/Command/User/Delete.php:46 OC\User\User->delete
Contents of Browser Error Console
n/a (server-side)
Suggested fix
UserDeleteHook is registered with $context->registerEventListener(BeforeUserDeletedEvent::class, UserDeleteHook::class), so ServiceEventListener already resolves it through the app's DI container. The services can be constructor-injected, and no Application instance is needed:
class UserDeleteHook implements IEventListener
{
public function __construct(
private ItemServiceV2 $itemService,
private FeedServiceV2 $feedService,
private FolderServiceV2 $folderService,
) {
}
public function handle(Event $event): void
{
if (!$event instanceof BeforeUserDeletedEvent) {
return;
}
$userId = $event->getUser()->getUID();
// order is important!
$this->itemService->deleteUser($userId);
$this->feedService->deleteUser($userId);
$this->folderService->deleteUser($userId);
}
}
- Dominant language
- PHP
- Stars
- 1k
- Forks
- 200
- Avg merge
- 20h 28m
- Merged PRs (30d)
- 32
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nextcloud/news
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
enhancement help wanted
Difficulty 3/5 1-2 days Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
replace mkdocs with somethingMay be free again @Grotax claimed this 95 days ago, and no pull request is open. Open
nextcloud/news#3887 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
bug help wanted upstream
Difficulty 3/5 1-2 days Newbie friendliness 58/100
nextcloud/news#3840 · 1 comment ·
Maintainers usually reply within 1 day
-
bug upstream
Difficulty 3/5 1-2 days Newbie friendliness 52/100
nextcloud/news#3822 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
0. Needs triage 35-feedback bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
wpgenius/stackfolio#22 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Automattic/static-site-importer#3024 ·
Maintainers usually reply within 1 day
-
[6.0]: Uncaught TypeError: can't access property "value", event.chart.scales.x.ticks[4] is undefinedOpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
phpmyadmin/phpmyadmin#20626 ·
Maintainers usually reply within 1 day