Not a bug All Image Attachments Converted to Links when Deleting Some Attachments

Affected version
2.0.1

rfc0001

Well-known member
This bug occurs in 1.5 and 2.0.

If you have a post with a lot of image attachments, and you go in and delete several of the attachments (both inline and the attachment itself), the remaining images are all converted to "view attachment xxxxx" links (like they are quoted).

Here is an example:
https://dvcinfo.com/forum/threads/holiday-disney-merchandise-deals.4024/post-44767

Note: if you click the links you can view the attachments so can tell they are still there.

I've disabled all add-ons that parse posts prior to saving this post, so have ruled them out as the cause. Let me know if you need additional information. This is an intermittent bug, but occurs about 75% of the time. It doesn't seem to occur if you delete the the ATTACHMENT code inline, save it, then come back and delete the actual attachment.

Thanks.
 

rfc0001

Well-known member
Here is the BB code for the post above showing all attachments inserted as FULL. Also, all attachments are from the same post.

Code:
[SIZE=6][SIZE=6][B]Over 40% off Disney Merchandise[/B][/SIZE][/SIZE]

[B][SIZE=5][URL='https://www.amazon.com/dp/B00CTNYLS8/?tag=dvcinfo03-20']Robin Hood 40th Anniversary DVD + Blu-ray + Digital[/URL][/SIZE][/B]

[B][ATTACH=full]19151[/ATTACH][/B]

[B][SIZE=5][URL='https://www.amazon.com/dp/B01MTES0GS/?tag=dvcinfo03-20']Disney Princess Floating Lanterns[/URL][/SIZE]
[ATTACH=full]19156[/ATTACH][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/B00QIIASSC/?tag=dvcinfo03-20']World of Disney Eye Found It Card Game[/URL]
[ATTACH=full]19133[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/0785168125/?tag=dvcinfo03-20']Marvel's Thor: The Dark World - The Art of the Movie (Slipcase)[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19123[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/1452122245/?tag=dvcinfo03-20']The Art of Finding Dory[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19124[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/1452135185/?tag=dvcinfo03-20']The Art of Inside Out[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19126[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/0811879631/?tag=dvcinfo03-20']The Art of Pixar: 25th Anniv.: The Complete Color Scripts and Select Art from 25 Years of Animation[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19127[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/1452155364/?tag=dvcinfo03-20']The Art of Moana[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19129[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/1452122237/?tag=dvcinfo03-20']The Art of Zootopia[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19130[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/1452117160/?tag=dvcinfo03-20']The Art of Frozen[/URL][/SIZE][/B]

[B][SIZE=5][ATTACH=full]19131[/ATTACH][/SIZE][/B]


[B][SIZE=5][URL='https://www.amazon.com/dp/B074K5J77B/?tag=dvcinfo03-20']Oral-B and Crest Kid's Holiday Pack Toothpaste, Disney's Princess Characters[/URL][/SIZE][/B]
[SIZE=5][B][ATTACH=full]19153[/ATTACH][/B][/SIZE]
 

Mike

XenForo developer
Staff member
Can you show a screenshot of the attachment area when you're editing the post?

No attachments are showing up at the bottom of the post. While clicking the link may display the attachment, this behavior is consistent with using an attachment that isn't associated with the post itself.
 

rfc0001

Well-known member
Can you show a screenshot of the attachment area when you're editing the post?

No attachments are showing up at the bottom of the post. While clicking the link may display the attachment, this behavior is consistent with using an attachment that isn't associated with the post itself.
They are associated with the same post:

1514758246247.png

I agree the behavior is consistent with them being associated with another post.
 

rfc0001

Well-known member
I agree the behavior is consistent with them being associated with another post.
As I say this, I wonder if rebuilding the threads (including post counts) would fix this? Seems Xenforo is confused about the threads the attachments are associated with.

ETA: No dice. Rebuilding threads (including post positions and counts) didn't fix (after editing and resaving thread)
 
Last edited:

rfc0001

Well-known member
So, after some extensive testing on two separate XF 2.0 boards upgraded from XF 1.5 and exhibiting this issue, I can only repro this from threads that were created with XF 1.5. I cannot repro this with new threads created in XF 2.0 using the same steps I created the XF 1.5 threads, however the previously created XF 1.5 thread still exhibit the behavior after being upgraded to XF 2.0. So, whatever is causing it appears to have been introduced by XF1.5 and is no longer occuring with XF 2.0. That said, it was easily reproducible in XF 1.5, I just never reported it since I hadn't controlled all the variable to determine if it was add-on related.
 

rfc0001

Well-known member
After some more time, I am still seeing this on new threads created with 2.0.

Using phpMyAdmin tell us what the xf_post.attach_count field shows for this post:

https://dvcinfo.com/forum/threads/holiday-disney-merchandise-deals.4024/post-44767
The attach_count is indeed 0 for the affected threads as you may have suspected. Changing this back to the correct number of attachments fixes the issue for that post (too bad there isn't a rebuild option to rebuild the attachment count based on actual attachments - note: I've tried all the rebuild options to no avail).

I have also verified the attachments are associated with the content_id (post ID) of the post.
 

rfc0001

Well-known member
As best as I can tell this is a race condition where the longer it takes for the thread to save the more likely this error condition is to occur. E.g. it tends to occur with threads with a lot of attachments, and occurs more often if all my thread parsing add-ons are enabled (although have been able to repro with add-ons disabled). I'm still trying to get a clean repro so I can repro it here.
 

rfc0001

Well-known member
Typically 10-20., although I've had this issue with as few as 2 attachments. Not a huge number, but combined with using your Amazon Parser, eBay Parser, Convert Image and Insert Attachment add-ons (all of which should be no-op on edit and I've reproed with all disabled) I'm thinking there is some timeout occuring or something.
 
Last edited:

rfc0001

Well-known member
So, here's how you can detect this issue (posts with attachments but with an attach_count of 0):
Code:
SELECT DISTINCT xf_post.post_id FROM xf_post
INNER JOIN xf_attachment
ON xf_post.post_id = xf_attachment.content_id
WHERE xf_post.attach_count = 0 AND xf_post.message LIKE '%[ATTACH=FULL]%' AND xf_attachment.content_type = 'post'
Can you run this on the Xenforo Community database just to make sure you aren't seeing the same issue occasionally?
 
Last edited:

Optic

Well-known member
I remember seeing another member with this issue:
https://xenforo.com/community/threads/problem-with-attachments.131417/

It might have something to do with the Convert Image addon, somehow your attachment records are becoming orphaned when you try to edit the post later. (I’m guessing that addon bypasses the XF core post editor when it directly downloads external images and attaches them to your post). Disabling addons probably won’t help if the attachment record is orphaned in the first place and maybe why you’re only seeing this issue on your older XF 1.5 topics vs a clean XF 2 install?
 

rfc0001

Well-known member
I remember seeing another member with this issue:
https://xenforo.com/community/threads/problem-with-attachments.131417/

It might have something to do with the Convert Image addon, somehow your attachment records are becoming orphaned when you try to edit the post later. (I’m guessing that addon bypasses the XF core post editor when it directly downloads external images and attaches them to your post). Disabling addons probably won’t help if the attachment record is orphaned in the first place and maybe why you’re only seeing this issue on your older XF 1.5 topics vs a clean XF 2 install?
All the attachments were created with Convert Image, and as you described disabling this add-on prior to editing them (when the issue occurs) doesn't prevent the issue. Also, I misspoke above - the issue does occur with 2.0 as well (with attachments created with Convert Image add-on but with Convert Image Add-on disabled prior to editing). Just curious, what does bypassing the core post editor not do?
 

Optic

Well-known member
Just curious, what does bypassing the core post editor not do?
Sorry I’m not a developer - I think you will need to follow up with the the addon developer - this addon is likely not using the default XF attachment Datawriter (which would have safeguards to prevent the attachment from being orphaned in the first place when you manually upload and attach an image in the editor).

Maybe a bug in the addon when you have too many attachments as you have said.

As it stands I don’t think it’s a core XF bug.
 

rfc0001

Well-known member
Sorry I’m not a developer - I think you will need to follow up with the the addon developer - this addon is likely not using the default XF attachment Datawriter (which would have safeguards to prevent the attachment from being orphaned in the first place when you manually upload and attach an image in the editor).

Maybe a bug in the addon when you have too many attachments as you have said.

As it stands I don’t think it’s a core XF bug.
At the end of the day it's all just data in the database, and the content_id in the attachment table is the post_id, and the post editor shows the attachment, so they aren't truly orphaned. What makes me think it's XF related is I can disable all attachments, edit a post and still repro the issue. Ultimately I don't care if it's XF or Convert Image, but given Convert Image is probably one of the most common add-ons on XF 1.5 and 2.0 it would be helpful if someone could look at the resulting data in the database and tell the author what is wrong about the way he is writing attachments. At least now I know the root cause (attach_count being set to 0) if we can just figure out "who" is setting it to 0. @Mike, Since I have a pretty good repro of this, is there some debugging/logging I can enable to figure this out? Thanks!
 

Mike

XenForo developer
Staff member
All the attachments were created with Convert Image
I think this is essentially pointing directly to the issue.

The issue here is specifically that the attach_count value in the database is incorrect. We haven't had any reports of this occurring in the past with the core attachment system, thus there is no rebuild for this. If a third-party add-on is inserting all of your attachments, the XF code isn't directly involved and therefore ensuring the attach_count value is set correctly is the responsibility of the add-on. If the value is too low, then XF won't think there are any attachments to a post and this could happen. (If the value is already incorrect, disabling add-ons won't resolve the issue because the DB contains incorrect values; to fully test, add-ons would need to be disabled and the issue would need to be reproduced entirely with the default functionality.)

The add-on author would really need to debug and diagnose this issue in their code.
 

rfc0001

Well-known member
If the value is already incorrect, disabling add-ons won't resolve the issue because the DB contains incorrect values; to fully test, add-ons would need to be disabled and the issue would need to be reproduced entirely with the default functionality
This explanation doesn't fit the behavior. If the attach_count were incorrect to begin with (when Convert Image saved the thread), the thread attachments would be displayed incorrectly immediately, which is not the case. The thread attachments are displayed correctly until the thread is edited and an attachment is deleted. When this occurs in XF2.0, I can revert the change and the images display correctly, which I can subsequently verify the attachment_count is correct, yet despite this fact, disabling all add-ons, and re-edited the thread will cause attachment_count to revert to 0 100% of the time (once the issue has occurred and is reverted). So, there is something about the specific thread (e.g. content) that seems to be is causing this. When this happens, is there something I can do to debug this further?
 
Last edited:

Mike

XenForo developer
Staff member
This explanation doesn't fit the behavior. If the attach_count were incorrect to begin with (when Convert Image saved the thread), the thread attachments would be displayed incorrectly immediately, which is not the case.
The way it works if that if the attach_count for a post is greater than 0, then we look up the attachments in that post (specifically, this is done for all posts on a page with attach_count > 0). As long as it's > 0, all of the attachments will be fetched and the issue won't be seen.

Thus, if the count is incorrect (say it's 1 when it should be 2) and you delete an attachment, we decrement the count to 0 and we no longer attempt to load attachments for that post and you see this issue. Testing at this point is generally too late -- the bug is that the attach_count value is wrong in the DB from the add-on that is inserting the attachments.

To test this issue without add-ons, it would involve disabling all of them, creating a new post (it can't be an existing one as the data may be wrong in the DB) and attaching files directly to the post and then deleting them. If you can trigger it with that, then please provide the exact steps so we can try to reproduce the issue.
 
Top