fix: Avoid failing to update the current version entry if there is none
Signed-off-by: Julius Härtl [email protected]
- Resolves: https://github.com/nextcloud/text/issues/3977
Summary
I managed to reproduce the error by having a file without a versions entry as it would be the case for files from before the upgrade to 25.
Steps to reproduce on latest master:
- Create a new text file
- Let it open but don't type
- Drop the created entry in oc_files_versions to simulate an older file
- Type something and save in the text app
The first attempt to save will not create a version as the size is 0 and https://github.com/nextcloud/server/blob/c3475f4dbbb9f5562218f058c3c53c38d084ad1b/apps/files_versions/lib/Storage.php#L227-L228 will not write a version in this case. However the logic in the FileEventsListener then would hit the case of the error message where there is no current version stored in the table.
It seemed reasonable to me to just create it in this case.
TODO
- [ ] ...
Checklist
- Code is properly formatted
- Sign-off message is added to all commits
- [ ] Tests (unit, integration, api and/or acceptance) are included
- [ ] Screenshots before/after for front-end changes
- [ ] Documentation (manuals or wiki) has been updated or is not required
- [ ] Backports requested where applicable (ex: critical bugfixes)
/backport to stable27
/backport to stable26
@artonge Unfortunately your approach doesn't work as it would try to create the version twice when creating and calling putContent, once with the NodeCreatedEvent and once with the NodeWrittenEvent. Did you have any concrete concern regarding my approach of just catching potential not found rows when trying to get the existing version?
I updated the condition, tests seem happy now :)
The backport to stable27 failed. Please do this backport manually.
# Switch to the target branch and update it
git checkout stable27
git pull origin stable27
# Create the new backport branch
git checkout -b fix/foo-stable27
# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123
# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable27
More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport
The backport to stable26 failed. Please do this backport manually.
# Switch to the target branch and update it
git checkout stable26
git pull origin stable26
# Create the new backport branch
git checkout -b fix/foo-stable26
# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123
# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable26
More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport
/backport to stable27
/backport to stable26
Hey @juliushaertl Still on issue. Just got this error on Nc 28.0.1
Dose this need to be merged to NC 28 ? please see error below
{"reqId":"FgbBuTFpl2rUhudfNB6o","level":3,"time":"2023-12-21T14:48:25-06:00","remoteAddr":"67.167.236.172","user":"admin","app":"no app in context","method":"PUT","url":"/remote.php/dav/files/admin/InstantUpload/Camera/20231221_080234.jpg","message":"Exception thrown: OCP\\AppFramework\\Db\\DoesNotExistException","userAgent":"Mozilla/5.0 (Android) Nextcloud-android/3.26.0","version":"28.0.1.1","exception":{"Exception":"OCP\\AppFramework\\Db\\DoesNotExistException","Message":"Did expect one result but found none when executing: query \"SELECT * FROM `*PREFIX*files_versions` WHERE (`file_id` = :dcValue1) AND (`timestamp` = :dcValue2)\"; ","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/public/AppFramework/Db/QBMapper.php","line":361,"function":"findOneQuery","class":"OCP\\AppFramework\\Db\\QBMapper","type":"->"},{"file":"/var/www/nextcloud/apps/files_versions/lib/Db/VersionsMapper.php","line":76,"function":"findEntity","class":"OCP\\AppFramework\\Db\\QBMapper","type":"->"},{"file":"/var/www/nextcloud/apps/files_versions/lib/Versions/LegacyVersionsBackend.php","line":253,"function":"findVersionForFileId","class":"OCA\\Files_Versions\\Db\\VersionsMapper","type":"->"},{"file":"/var/www/nextcloud/apps/files_versions/lib/Versions/VersionManager.php","line":152,"function":"updateVersionEntity","class":"OCA\\Files_Versions\\Versions\\LegacyVersionsBackend","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php","line":232,"function":"updateVersionEntity","class":"OCA\\Files_Versions\\Versions\\VersionManager","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php","line":106,"function":"post_write_hook","class":"OCA\\Files_Versions\\Listener\\FileEventsListener","type":"->"},{"file":"/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php","line":86,"function":"handle","class":"OCA\\Files_Versions\\Listener\\FileEventsListener","type":"->"},{"file":"/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php","line":230,"function":"__invoke","class":"OC\\EventDispatcher\\ServiceEventListener","type":"->"},{"file":"/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php","line":59,"function":"callListeners","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php","line":94,"function":"dispatch","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php","line":106,"function":"dispatch","class":"OC\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Node/HookConnector.php","line":109,"function":"dispatchTyped","class":"OC\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/legacy/OC_Hook.php","line":105,"function":"postWrite","class":"OC\\Files\\Node\\HookConnector","type":"->"},{"file":"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php","line":479,"function":"emit","class":"OC_Hook","type":"::"},{"file":"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php","line":404,"function":"emitPostHooks","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":1137,"function":"put","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":492,"function":"updateFile","class":"Sabre\\DAV\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPut","class":"Sabre\\DAV\\CorePlugin","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/apps/dav/lib/Server.php","line":370,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/remote.php","line":172,"args":["/var/www/nextcloud/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/nextcloud/lib/public/AppFramework/Db/QBMapper.php","Line":283,"CustomMessage":"Exception thrown: OCP\\AppFramework\\Db\\DoesNotExistException"},"id":"6584b598e47a0"}
Seems the code has been reworked in https://github.com/nextcloud/server/commit/cec0b310a5af84d5afae4afa2449840dcdca56be again, won't have time to dive into that, but #41174 is tracking this i think
Same problem in 28.0.6.