Fixed Error when retrieving attachments

Affected version
xF2 Beta 5


When I go to content->attachments and get the message:

Server error log:
TypeError: Argument 1 passed to XF\Attachment\Post::getContainerLink() must be an instance of XF\Mvc\Entity\Entity, null given, called in /var/www/ on line 65 src/XF/Attachment/Post.php:95

Stack trace:
#0 src/XF/Entity/Attachment.php(65): XF\Attachment\Post->getContainerLink(NULL)
#1 [internal function]: XF\Entity\Attachment->getContainerLink()
#2 src/XF/Template/Templater.php(846): call_user_func_array(Array, Array)
#3 internal_data/code_cache/templates/l2/s0/admin/attachment_list.php(120): XF\Template\Templater->method(Object(XF\Entity\Attachment), 'getContainerLin...', Array)
#4 src/XF/Template/Templater.php(1133): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array)
#5 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('attachment_list', Array)
#6 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#7 src/XF/Mvc/Dispatcher.php(332): XF\Mvc\Renderer\Html->renderView('XF:Attachment\\L...', 'admin:attachmen...', Array)
#8 src/XF/Mvc/Dispatcher.php(303): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#9 src/XF/Mvc/Dispatcher.php(44): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#10 src/XF/App.php(1831): XF\Mvc\Dispatcher->run()
#11 src/XF.php(328): XF\App->run()
#12 admin.php(13): XF::runApp('XF\\Admin\\App')
#13 {main}

Request state:
array(4) {
  ["url"] => string(23) "/admin.php?attachments/"
  ["referrer"] => string(39) ""
  ["_GET"] => array(1) {
    ["attachments/"] => string(0) ""
  ["_POST"] => array(0) {
Last edited:

Chris D

XenForo developer
Staff member
That sounds like an attachment which is still associated with a post that no longer exists.

I think we can workaround that, but it basically shouldn't ever happen unless an add-on is involved or data has been manually removed from the database.


Hi Chris D,

the data was not deleted manually, but I had uninstalled XenForo Media Gallery I wanted to test something. I guess that's where the mistake came from.

Chris D

XenForo developer
Staff member
No, I don't think it is. The error is specifically related to the Post attachment handler. So it still seems to me like it's related to an attachment which can no longer find its content.

We'll look into it though and report back once we've confirmed the likely cause.

Chris D

XenForo developer
Staff member
We can confirm that this is certainly what I suspected which is that the host content (a post, in this case) had been deleted but the attachment remained.

This was likely an issue in XF1 too but we handled the situation better.

Sorted now for XF2 Beta 6, thanks!