Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: TypeError: OCP\AppFramework\Db\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\AppFramework\Db\Entity, null given #37407

Closed
6 of 9 tasks
Tracked by #1846 ...
BJKle opened this issue Mar 26, 2023 · 24 comments · Fixed by #38125 or #38224
Assignees
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 26-feedback bug

Comments

@BJKle
Copy link

BJKle commented Mar 26, 2023

⚠️ This issue respects the following points: ⚠️

  • This is a bug, not a question or a configuration/webserver/proxy issue.
  • This issue is not already reported on Github (I've searched it).
  • Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
  • Nextcloud Server is running on 64bit capable CPU, PHP and OS.
  • I agree to follow Nextcloud's Code of Conduct.

Bug description

In my error log I can find the following errors every 12 hours since updating to NC 26 and PHP 8.2:

Undefined array key 169178 at /var/www/nextcloud/apps/files_versions/lib/Storage.php#615

TypeError: OCP\AppFramework\Db\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\AppFramework\Db\Entity, null given, called in /var/www/nextcloud/apps/files_versions/lib/Storage.php on line 615

Steps to reproduce

don't know

Expected behavior

no error

Installation method

Community Manual installation with Archive

Operating system

Debian/Ubuntu

PHP engine version

Other

Web server

Nginx

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

No response

List of activated Apps

Enabled:
  - activity: 2.18.0
  - admin_audit: 1.16.0
  - cloud_federation_api: 1.9.0
  - dav: 1.25.0
  - federatedfilesharing: 1.16.0
  - files: 1.21.1
  - files_pdfviewer: 2.7.0
  - files_rightclick: 1.5.0
  - files_sharing: 1.18.0
  - files_trashbin: 1.16.0
  - files_versions: 1.19.1
  - geoblocker: 0.5.7
  - groupfolders: 14.0.0
  - logreader: 2.11.0
  - lookup_server_connector: 1.14.0
  - notes: 4.7.2
  - notifications: 2.14.0
  - oauth2: 1.14.0
  - password_policy: 1.16.0
  - photos: 2.2.0
  - previewgenerator: 5.2.1
  - privacy: 1.10.0
  - provisioning_api: 1.16.0
  - recommendations: 1.5.0
  - related_resources: 1.1.0-alpha1
  - serverinfo: 1.16.0
  - settings: 1.8.0
  - sharebymail: 1.16.0
  - systemtags: 1.16.0
  - text: 3.7.2
  - theming: 2.1.1
  - twofactor_backupcodes: 1.15.0
  - updatenotification: 1.16.0
  - viewer: 1.10.0
  - workflowengine: 2.8.0

Nextcloud Signing status

No response

Nextcloud Logs

[cron] Error: TypeError: OCP\AppFramework\Db\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\AppFramework\Db\Entity, null given, called in /var/www/nextcloud/apps/files_versions/lib/Storage.php on line 615 at <<closure>>

0. /var/www/nextcloud/apps/files_versions/lib/Storage.php line 615
   OCP\AppFramework\Db\QBMapper->delete()
1. /var/www/nextcloud/apps/files_versions/lib/BackgroundJob/ExpireVersions.php line 69
   OCA\Files_Versions\Storage::expireOlderThanMaxForUser()
2. /var/www/nextcloud/lib/private/User/Manager.php line 639
   OCA\Files_Versions\BackgroundJob\ExpireVersions->OCA\Files_Versions\BackgroundJob\{closure}("*** sensitive parameters replaced ***")
3. /var/www/nextcloud/apps/files_versions/lib/BackgroundJob/ExpireVersions.php line 64
   OC\User\Manager->callForSeenUsers()
4. /var/www/nextcloud/lib/public/BackgroundJob/Job.php line 78
   OCA\Files_Versions\BackgroundJob\ExpireVersions->run()
5. /var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php line 103
   OCP\BackgroundJob\Job->start()
6. /var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php line 93
   OCP\BackgroundJob\TimedJob->start()
7. /var/www/nextcloud/cron.php line 152
   OCP\BackgroundJob\TimedJob->execute()

at 2023-03-25T18:40:02+01:00

Additional info

No response

@BJKle BJKle added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels Mar 26, 2023
@szaimen
Copy link
Contributor

szaimen commented Mar 26, 2023

Cc @artonge

@solracsf solracsf changed the title [Bug]: /var/www/nextcloud/apps/files_versions/lib/Storage.php#615 [Bug]: TypeError: OCP\AppFramework\Db\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\AppFramework\Db\Entity, null given Mar 26, 2023
@BJKle
Copy link
Author

BJKle commented Mar 26, 2023

The following new code line 615 is the cause:
$versionsMapper->delete($versionEntities[$version->getId()]);
Merged on Jan 26, 2023

@artonge artonge self-assigned this Mar 29, 2023
@Kalle73kw
Copy link

Is there a workaround or fix already?

@erwdavid
Copy link

same thing with NC 26 on FreeBSD, php 8.2
It appears in cron jobs

@Kalle73kw
Copy link

Deleting all versions (php occ versions:cleanup) and deactivating the versions app stopped the errors at least for now. 💁🏻‍♂️

@AndyXheli
Copy link

AndyXheli commented Apr 20, 2023

Same issue running NC 26.0.1 on Ubuntu, PHP 8.1, MySQL 10.3.38

{"reqId":"c4QecNyf5eGERWPEwLr6","level":3,"time":"2023-04-20T14:10:25+00:00","remoteAddr":"","user":"--","app":"cron","method":"","url":"--","message":"OCP\\AppFramework\\Db\\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\\AppFramework\\Db\\Entity, null given, called in /var/www/nextcloud/apps/files_versions/lib/Storage.php on line 615","userAgent":"--","version":"26.0.1.1","exception":{"Exception":"TypeError","Message":"OCP\\AppFramework\\Db\\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\\AppFramework\\Db\\Entity, null given, called in /var/www/nextcloud/apps/files_versions/lib/Storage.php on line 615","Code":0,"Trace":[{"file":"/var/www/nextcloud/apps/files_versions/lib/Storage.php","line":615,"function":"delete","class":"OCP\\AppFramework\\Db\\QBMapper","type":"->"},{"file":"/var/www/nextcloud/apps/files_versions/lib/BackgroundJob/ExpireVersions.php","line":69,"function":"expireOlderThanMaxForUser","class":"OCA\\Files_Versions\\Storage","type":"::"},{"file":"/var/www/nextcloud/lib/private/User/Manager.php","line":639,"function":"OCA\\Files_Versions\\BackgroundJob\\{closure}","class":"OCA\\Files_Versions\\BackgroundJob\\ExpireVersions","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/files_versions/lib/BackgroundJob/ExpireVersions.php","line":70,"function":"callForSeenUsers","class":"OC\\User\\Manager","type":"->"},{"file":"/var/www/nextcloud/lib/public/BackgroundJob/Job.php","line":78,"function":"run","class":"OCA\\Files_Versions\\BackgroundJob\\ExpireVersions","type":"->"},{"file":"/var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php","line":103,"function":"start","class":"OCP\\BackgroundJob\\Job","type":"->"},{"file":"/var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php","line":93,"function":"start","class":"OCP\\BackgroundJob\\TimedJob","type":"->"},{"file":"/var/www/nextcloud/cron.php","line":152,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->"}],"File":"/var/www/nextcloud/lib/public/AppFramework/Db/QBMapper.php","Line":96,"CustomMessage":"--"},"id":"644149ddb5bfc"}

Error when running it via occ versions:expire

 sudo -u www-data php /var/www/nextcloud/occ versions:expire
    3 [->--------------------------]An unhandled exception has been thrown:
TypeError: OCP\AppFramework\Db\QBMapper::delete(): Argument #1 ($entity) must be of type OCP\AppFramework\Db\Entity, null given, called in /var/www/nextcloud/apps/files_versions/lib/Storage.php on line 615 and defined in /var/www/nextcloud/lib/public/AppFramework/Db/QBMapper.php:96
Stack trace:
#0 /var/www/nextcloud/apps/files_versions/lib/Storage.php(615): OCP\AppFramework\Db\QBMapper->delete()
#1 /var/www/nextcloud/apps/files_versions/lib/Command/ExpireVersions.php(110): OCA\Files_Versions\Storage::expireOlderThanMaxForUser()
#2 /var/www/nextcloud/apps/files_versions/lib/Command/ExpireVersions.php(97): OCA\Files_Versions\Command\ExpireVersions->expireVersionsForUser()
#3 /var/www/nextcloud/lib/private/User/Manager.php(639): OCA\Files_Versions\Command\ExpireVersions->OCA\Files_Versions\Command\{closure}()
#4 /var/www/nextcloud/apps/files_versions/lib/Command/ExpireVersions.php(98): OC\User\Manager->callForSeenUsers()
#5 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files_Versions\Command\ExpireVersions->execute()
#6 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#7 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#8 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#9 /var/www/nextcloud/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run()
#10 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#11 /var/www/nextcloud/occ(11): require_once('...')

@vanoc
Copy link

vanoc commented Apr 24, 2023

same error.
Centos 8, PHP 8.1.18, Nextcloud 26.0.1

@erwdavid
Copy link

erwdavid commented Apr 24, 2023 via email

@WolkeOsch
Copy link

Made upgrade to v26 (php 8.1.2 - ubuntu 22 ) yesterday. Got the same error message within 12 hours.

@BJKle
Copy link
Author

BJKle commented Apr 30, 2023

@artonge Any development? Could you please post a status and an timeline? Thank you.

@solracsf
Copy link
Member

solracsf commented May 8, 2023

Fix released at #38125

@BJKle
Copy link
Author

BJKle commented May 9, 2023

@solracsf
Thank you.
replaced the old version with your fix.
The "TypeError" is gone but the 1st error:
Undefined array key 171289 at /var/www/nextcloud/apps/files_versions/lib/Storage.php#616
is still present
now when calling the newly introduced code:

            $versionEntity = $versionEntities[$version->getId()];

instead of 2 every 12 hours I get 16 now.

@solracsf
Copy link
Member

The undefined array key is a duplicate of nextcloud/groupfolders#2343

@solracsf
Copy link
Member

solracsf commented May 10, 2023

@BJKle @AndyXheli can you replace :

$versionEntity = $versionEntities[$version->getId()];

with

$versionEntity = isset($versionEntities[$version->getId()]) ? $versionEntities[$version->getId()] : null;

And see if helps?

@BJKle
Copy link
Author

BJKle commented May 11, 2023

Thanks. But I’ll just wait for the official version.

@solracsf
Copy link
Member

solracsf commented May 11, 2023

Did you know that an official version will come out only if someone (like me) reproduces the bug and helps fix it?
But i understand, you don't want to lose your time, I won't lose mine either 😉

@AndyXheli
Copy link

@solracsf I can give it a test what file would you like me to change ?

@solracsf
Copy link
Member

After aplying #38125
Edit that portion again and do #37407 (comment)

@solracsf
Copy link
Member

solracsf commented May 11, 2023

Final code is:

foreach ($versions as $version) {
	$internalPath = $version->getInternalPath();
	\OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $internalPath, 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT]);

	$versionEntity = isset($versionEntities[$version->getId()]) ? $versionEntities[$version->getId()] : null;
	if (!is_null($versionEntity)) {
		$versionsMapper->delete($versionEntity);
	}

	$version->delete();
	\OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $internalPath, 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT]);
}

@AndyXheli
Copy link

Thank you! I'll give it a try and keep you posted.

@AndyXheli
Copy link

AndyXheli commented May 12, 2023

@solracsf Looks good on my server. Before the change

image

After apply the patches ran an occ with no issues

image

Also i did see the

Undefined array key 943358 at /var/www/nextcloud/apps/files_versions/lib/Storage.php#615

in error logs. After applying it seems to be gone.

@erwdavid
Copy link

erwdavid commented May 12, 2023 via email

@solracsf
Copy link
Member

Thanks for your feedback. Patch at #38224

@AndyXheli

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 26-feedback bug
Projects
None yet
9 participants