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

fix: Avoid failing to update the current version entry if there is none #38800

Merged
merged 4 commits into from Jun 23, 2023

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Jun 13, 2023

Signed-off-by: Julius Härtl jus@bitgrid.net

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

if ($file->getSize() === 0) {
return false;
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

Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliushaertl juliushaertl requested review from artonge, icewind1991, a team, ArtificialOwl and come-nc and removed request for a team June 13, 2023 20:15
@juliushaertl juliushaertl added bug 3. to review Waiting for reviews labels Jun 13, 2023
@szaimen szaimen added this to the Nextcloud 28 milestone Jun 13, 2023
Signed-off-by: Louis Chemineau <louis@chmn.me>
Copy link
Contributor

@artonge artonge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this only happen when file size is 0, I think adding a special logic is better than catching exceptions as they can be caused be something else.

I pushed a commit to slightly change your fix. Let me know what you think.

Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliushaertl juliushaertl added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jun 21, 2023
@juliushaertl
Copy link
Member Author

/backport to stable27

@juliushaertl
Copy link
Member Author

/backport to stable26

@juliushaertl
Copy link
Member Author

juliushaertl commented Jun 22, 2023

@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?

Signed-off-by: Louis Chemineau <louis@chmn.me>
@artonge
Copy link
Contributor

artonge commented Jun 22, 2023

I updated the condition, tests seem happy now :)

@juliushaertl juliushaertl merged commit 05f360c into master Jun 23, 2023
39 checks passed
@juliushaertl juliushaertl deleted the bugfix/noid/version-update-or-insert branch June 23, 2023 08:40
@backportbot-nextcloud
Copy link

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

@backportbot-nextcloud
Copy link

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

@solracsf
Copy link
Member

/backport to stable27

@juliushaertl
Copy link
Member Author

/backport to stable26

@AndyXheli
Copy link
Contributor

AndyXheli commented Dec 21, 2023

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"}

@juliushaertl
Copy link
Member Author

Seems the code has been reworked in cec0b31 again, won't have time to dive into that, but #41174 is tracking this i think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug
Projects
None yet
6 participants