XF 2.2 How do I find where an "attachment missing" is coming from?

Semper Fidelis

Active member
Below is one example of an error I'm getting about missing attachments in the error log.

When I search the database, however, I cannot find the attachment referenced anywhere except in the error log table.

How do I find what's triggering the error and a few other annoying logs that reference other attachments that cannot be found?

Is there any way to clean up attachments and their references so all posts either map to existing attachments and, if not, those attachment references can be pruned?

Code:
League\Flysystem\FileNotFoundException: File not found at path: attachments/5/5023-ccfc4f399ef4ec51cf5f6be7a0b66e31.data src/vendor/league/flysystem/src/Filesystem.php:389
Generated by: Anthony DeNicola Sep 4, 2023 at 7:04 PM
Stack trace
#0 src/vendor/league/flysystem/src/Filesystem.php(194): League\Flysystem\Filesystem->assertPresent('attachments/5/5...')
#1 [internal function]: League\Flysystem\Filesystem->readStream('attachments/5/5...', Array)
#2 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(431): call_user_func_array('League\\Flysyste...', Array)
#3 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(395): League\Flysystem\EventableFilesystem\EventableFilesystem->callFilesystemMethod('readStream', Array)
#4 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(154): League\Flysystem\EventableFilesystem\EventableFilesystem->delegateMethodCall('readStream', Array)
#5 src/vendor/league/flysystem/src/MountManager.php(345): League\Flysystem\EventableFilesystem\EventableFilesystem->readStream('attachments/5/5...')
#6 src/XF/Pub/View/Attachment/View.php(25): League\Flysystem\MountManager->readStream('attachments/5/5...')
#7 src/XF/Mvc/Renderer/AbstractRenderer.php(91): XF\Pub\View\Attachment\View->renderRaw()
#8 src/XF/Mvc/Renderer/Raw.php(39): XF\Mvc\Renderer\AbstractRenderer->renderViewObject('XF:Attachment\\V...', '', Array)
#9 src/XF/Mvc/Dispatcher.php(460): XF\Mvc\Renderer\Raw->renderView('XF:Attachment\\V...', '', Array)
#10 src/XF/Mvc/Dispatcher.php(442): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Raw), Object(XF\Mvc\Reply\View))
#11 src/XF/Mvc/Dispatcher.php(402): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Raw), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(60): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'raw')
#13 src/XF/App.php(2487): XF\Mvc\Dispatcher->run()
#14 src/XF.php(524): XF\App->run()
#15 index.php(20): XF::runApp('XF\\Pub\\App')
#16 {main}
 
That's going to be attachment 5023 being in the database, but the underlying attachment data is missing (from the local filesystem in a default XenForo setup). For that attachment, it's expecting to find the underlying attachment at this location (but it isn't there for whatever reason):

internal_data/attachments/5/5023-ccfc4f399ef4ec51cf5f6be7a0b66e31.data
 
I searched for 5023-ccfc4f399ef4ec51cf5f6be7a0b66e31.dat
You won't find that string (or any other .dat) in the dababase as it's a constructed filename:
5023 is the attachment data id and ccfc4f399ef4ec51cf5f6be7a0b66e31 the file hash.

That's going to be attachment 5023 being in the database,
Ther is a high chance that attachment data ID 5023 belongs to attachment ID 5023 - but this isnt't necessarily the case.
Is is guaranteed though that 5023-ccfc4f399ef4ec51cf5f6be7a0b66e31.dat is the file for attachment data ID 5023.
 
You won't find that string (or any other .dat) in the dababase as it's a constructed filename:
5023 is the attachment data id and ccfc4f399ef4ec51cf5f6be7a0b66e31 the file hash.


Ther is a high chance that attachment data ID 5023 belongs to attachment ID 5023 - but this isnt't necessarily the case.
Is is guaranteed though that 5023-ccfc4f399ef4ec51cf5f6be7a0b66e31.dat is the file for attachment data ID 5023.
Oh ya, that's right... This will get you the attachment ID:

SQL:
SELECT attachment_id FROM xf_attachment_data LEFT JOIN xf_attachment ON (xf_attachment_data.data_id = xf_attachment.data_id) WHERE attachment_id = 5023
 
I've been trying, unsuccessfully, to get rid of missing attachment errors as pasted below. I've searched the attachment Id (e.g. 4381) and browsed to the post that it is attached and then delete the attachment within the post and res-ave the post. I've also re-attached attachments that are triggering missing attachments even thought hey are there.

In this case, attachment ID 4381 is not even in the xf_attachments table so I don't know what to do. Am I doomed to have missing attachment errors or is there a way to clean up something, somewhere in the database where this attachment is referenced?

Code:
League\Flysystem\FileNotFoundException: File not found at path: attachments/4/4381-c7de155e5d23baa5b5f4d2ff265d73fe.data src/vendor/league/flysystem/src/Filesystem.php:389
Generated by: Unknown account Sep 11, 2023 at 11:15 PM
Stack trace
#0 src/vendor/league/flysystem/src/Filesystem.php(194): League\Flysystem\Filesystem->assertPresent('attachments/4/4...')
#1 [internal function]: League\Flysystem\Filesystem->readStream('attachments/4/4...', Array)
#2 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(431): call_user_func_array('League\\Flysyste...', Array)
#3 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(395): League\Flysystem\EventableFilesystem\EventableFilesystem->callFilesystemMethod('readStream', Array)
#4 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(154): League\Flysystem\EventableFilesystem\EventableFilesystem->delegateMethodCall('readStream', Array)
#5 src/vendor/league/flysystem/src/MountManager.php(345): League\Flysystem\EventableFilesystem\EventableFilesystem->readStream('attachments/4/4...')
#6 src/XF/Pub/View/Attachment/View.php(25): League\Flysystem\MountManager->readStream('attachments/4/4...')
#7 src/XF/Mvc/Renderer/AbstractRenderer.php(91): XF\Pub\View\Attachment\View->renderRaw()
#8 src/XF/Mvc/Renderer/Raw.php(39): XF\Mvc\Renderer\AbstractRenderer->renderViewObject('XF:Attachment\\V...', '', Array)
#9 src/XF/Mvc/Dispatcher.php(460): XF\Mvc\Renderer\Raw->renderView('XF:Attachment\\V...', '', Array)
#10 src/XF/Mvc/Dispatcher.php(442): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Raw), Object(XF\Mvc\Reply\View))
#11 src/XF/Mvc/Dispatcher.php(402): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Raw), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(60): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'raw')
#13 src/XF/App.php(2487): XF\Mvc\Dispatcher->run()
#14 src/XF.php(524): XF\App->run()
#15 index.php(20): XF::runApp('XF\\Pub\\App')
#16 {main}
 
Just to update any who has to deal with this annoyance in the server logs.

For the few remaining attachments that kept showing up as missing, I just made a copy of another .attach file that pointed to a generic image and uploaded the .attach file into the internal-data/attachments directory.

It would have been nice if a Xenforo Dev had offered some insight on how an attachment that appears nowhere in a post after deleting it can still generate the errors, but I've figured out a way to avoid the constant error messages.
 
The attachments are being viewed directly by ID rather than in a post. Are you looking at 4381 as the attachment_id or data_id? In that path 4381 is the data_id. It must be in there otherwise it'd be physically impossible for it to know what the path it's trying to load is.

Unless you manually deleted files I'm not sure though how you'd have started getting these, the data files don't get deleted until attachments are hard deleted.
 
The attachments are being viewed directly by ID rather than in a post. Are you looking at 4381 as the attachment_id or data_id? In that path 4381 is the data_id. It must be in there otherwise it'd be physically impossible for it to know what the path it's trying to load is.

Unless you manually deleted files I'm not sure though how you'd have started getting these, the data files don't get deleted until attachments are hard deleted.
The “how“ .attach files are missing is probably due to BD_atachment AddOn. Even though I had it set to keep files on server I don’t think it did for some. Thanks for the note on the data_id.
 
I've been trying, unsuccessfully, to get rid of missing attachment errors as pasted below. I've searched the attachment Id (e.g. 4381) and browsed to the post that it is attached and then delete the attachment within the post and res-ave the post. I've also re-attached attachments that are triggering missing attachments even thought hey are there.

In this case, attachment ID 4381 is not even in the xf_attachments table so I don't know what to do. Am I doomed to have missing attachment errors or is there a way to clean up something, somewhere in the database where this attachment is referenced?

Code:
League\Flysystem\FileNotFoundException: File not found at path: attachments/4/4381-c7de155e5d23baa5b5f4d2ff265d73fe.data src/vendor/league/flysystem/src/Filesystem.php:389
The number you get from the file path is the data_id, NOT attachment_id as already explained in https://xenforo.com/community/threa...nt-missing-is-coming-from.216405/post-1645248
 
The number you get from the file path is the data_id, NOT attachment_id as already explained in https://xenforo.com/community/threa...nt-missing-is-coming-from.216405/post-1645248
I appreciate you and @mattrogowski answering this. I suffer from a visual impairment and I think I was shown that at least 3 times and it finally sank in. It certainly explains a lot after browsing to a post id that corresponded to what I thought was the attachment id. When I searched by data id in the xf_attachment table I figured out that there ware a lot of missing files in the media gallery. That seems to be where they are clustered.

There's nothing more annoying than believing you've excised an attachment only to see it keep popping up in the server error logs. My lack of attention to detail explains why.
 
OK, now I'm flummoxed. I thought I cracked the code on finding attachments. I've checked and re-checked and there is no attachment with data_id of 4593. Is there another way this error could have been triggered 5 times? Maybe a caching issue? I might have found and resolved this already and the search index thinks it's there? Thoughts?

Code:
[LIST]
[*]League\Flysystem\FileNotFoundException: File not found at path: attachments/4/4593-737bf43379656942487fcf5be0c7901d.data
[*]src/vendor/league/flysystem/src/Filesystem.php:389
[*]Generated by: [URL='https://puritanboard.com/admin.php?users/semper-fidelis.836/edit']Semper Fidelis[/URL]
[*]Sep 15, 2023 at 12:30 PM
[/LIST]
[HEADING=2]Stack trace[/HEADING]
#0 src/vendor/league/flysystem/src/Filesystem.php(194): League\Flysystem\Filesystem->assertPresent('attachments/4/4...')
#1 [internal function]: League\Flysystem\Filesystem->readStream('attachments/4/4...', Array)
#2 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(431): call_user_func_array('League\\Flysyste...', Array)
#3 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(395): League\Flysystem\EventableFilesystem\EventableFilesystem->callFilesystemMethod('readStream', Array)
#4 src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php(154): League\Flysystem\EventableFilesystem\EventableFilesystem->delegateMethodCall('readStream', Array)
#5 src/vendor/league/flysystem/src/MountManager.php(345): League\Flysystem\EventableFilesystem\EventableFilesystem->readStream('attachments/4/4...')
#6 src/XF/Pub/View/Attachment/View.php(25): League\Flysystem\MountManager->readStream('attachments/4/4...')
#7 src/XF/Mvc/Renderer/AbstractRenderer.php(91): XF\Pub\View\Attachment\View->renderRaw()
#8 src/XF/Mvc/Renderer/Raw.php(39): XF\Mvc\Renderer\AbstractRenderer->renderViewObject('XF:Attachment\\V...', '', Array)
#9 src/XF/Mvc/Dispatcher.php(460): XF\Mvc\Renderer\Raw->renderView('XF:Attachment\\V...', '', Array)
#10 src/XF/Mvc/Dispatcher.php(442): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Raw), Object(XF\Mvc\Reply\View))
#11 src/XF/Mvc/Dispatcher.php(402): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Raw), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(60): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'raw')
#13 src/XF/App.php(2487): XF\Mvc\Dispatcher->run()
#14 src/XF.php(524): XF\App->run()
#15 index.php(20): XF::runApp('XF\\Pub\\App')[/code
 
It's either still in the database, has been deleted since the error happened, or you've got multiple database instances (which I guess you don't actually have) - it would have to be querying it fresh from the database to get the full 737bf43379656942487fcf5be0c7901d hash there.
 
It's either still in the database, has been deleted since the error happened, or you've got multiple database instances (which I guess you don't actually have) - it would have to be querying it fresh from the database to get the full 737bf43379656942487fcf5be0c7901d hash there.
I only have one db instance. There is no 4593 data id. Where would I search for the hash? I searched the entire database using %737bf43379656942487fcf5be0c7901d% and it only found the hash in xf_error_log.
 
It would be the file_hash column in xf_attachment_data. If it's definitely not there then the attachment data has probably been cleaned up since and the row has been deleted since the error happened.
 
Back
Top Bottom