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}
 
Normally I'd say it shouldn't be possible to get such an error without a corresponding record in the database.

Try these queries to see if they return anything:
Code:
SELECT * FROM xf_attachment WHERE data_id = 4593
SELECT * FROM xf_attachment_data WHERE data_id = 4593
SELECT * FROM xf_attachment_data WHERE file_hash = '737bf43379656942487fcf5be0c7901d'

Redis isn't used for anything related to attachments (wich standard XenForo, might be the case if Add-ons are used - I don't know).
 
Could it be Cloudflare's cache?
No. Even if a page that contains a (now gone) attachment is served from coudflare cache (which won't happen unless you configure CouldFlare to cache dynamic pages) the resulting request to the origin would not produce such an error - it just would generate an eror message for the client that the attachment doesn't exist.

The error message should show which URL actuall ygenerated the error.

Can you re-produce it by accessing that URL again?
 
No. Even if a page that contains a (now gone) attachment is served from coudflare cache (which won't happen unless you configure CouldFlare to cache dynamic pages) the resulting request to the origin would not produce such an error - it just would generate an eror message for the client that the attachment doesn't exist.

The error message should show which URL actuall ygenerated the error.

Can you re-produce it by accessing that URL again?
The only thing I have is the error log that I've pasted in full. I don't know what URL generated it.
 
Thats strange :)

I tried to simulate the error you got (by intentionally deleting the file) and the eror log entry does show the URL that generated the error:
View attachment 291145

Maybe you could re-check the error log again and post a screenshot (like I did)?
Thanks for showing me where to look. I was pasting the reported error part and not the Request State. Unfortunately, I deleted the error.

That actually will save me a ton of time because I've been searching for the data id and didn't even see that the referring URL was in that portion.

IIf it re-occurs then I'll post it. Right now, the reported errors is gone.
 
So if I understand correctly, to avoid these errors I need to search the attachments ID in the database and delete everything related to it?

I have the attachment ID in the URL in the error log showing as:
["url"] => string(19) "/attachments/11326/"

When I navigate to this URL I get an XF front end error that this attachment doesn’t exists but it doesn’t trigger another error log in the ACP
 
If this is related to the error you posted in the other thread...
League\Flysystem\FileNotFoundException: File not found at path: attachments/9/9609-f935b1f5e093cecfb3b4bd558ebfb35d.data

9609 would be your attachment data id (not necessarily the same as your attachment id). You can get the attachment id for that data record with a SQL query like so:
SQL said:
SELECT attachment_id FROM xf_attachment WHERE data_id = 9609;

Then you can at least know the attachment with the missing data and go from there...
 
If this is related to the error you posted in the other thread...


9609 would be your attachment data id (not necessarily the same as your attachment id). You can get the attachment id for that data record with a SQL query like so:


Then you can at least know the attachment with the missing data and go from there...
Thanks. So the URL string in the error message doesn't mean anything?

It looks like this:


Code:
League\Flysystem\FileNotFoundException: File not found at path: attachments/9/9609-f935b1f5e093cecfb3b4bd558ebfb35d.data src/addons/DigitalPoint/Cloudflare/League/Flysystem/Adapter/R2.php:132
Generated by: Unknown account 3/10/23 at 20:49

Request state
array(4) {
  ["url"] => string(19) "/attachments/11326/"
 
The URL string in the error will tell you what URL triggered the problem, but that's not how you would search the database. Sometimes I'll use the URL as it is useful to find a post where the attachment itself is missing. You can sometimes use that URL string to get to the forum thread where the attachment is missing.

Many times, however, you have to search the xf_attachments table for the data_id that corresponds to the attachment number being reported (see in my first post it was 4393).

Once you find the row in the xf_attachments you can find the post id where the attachment is located (or in some cases it's in an AddOn location). You can go directly to the post id by https://forumurl.com/posts/post-id. From there you can edit the post and delete the attachment that's missing from the post.

Honestly, I've gotten weary of keeping up with the error reports as I've lost quite a few.
 
The hash is stored in xf_attachment_data and the container information is in xf_attachment, so you'd have to query like this:

Code:
select * from xf_attachment join xf_attachment_data using (data_id) where file_hash = 'xxx';

Change xxx to the hash, and the returned row will have a value for the content type and ID the attachment is linked with.
 
The hash is stored in xf_attachment_data and the container information is in xf_attachment, so you'd have to query like this:

Code:
select * from xf_attachment join xf_attachment_data using (data_id) where file_hash = 'xxx';

Change xxx to the hash, and the returned row will have a value for the content type and ID the attachment is linked with.
Thanks. I'm trying to figure out the post id or thread id the attachment is associated with the attachment. Is there a way to see this by running a query?
 
https://www.website.tld/posts/<id>
or
https://www.website.tld/threads/does-not-matter.1/post-<id>/
or
SELECT thread_id FROM xf_post WHERE post_id = <id>
or ...

Almost endless possibilities :)
 
Last edited:
Top Bottom