Attachment-Sitemap will publish attachments with unpublished parent-posts
What did you expect to happen?
The attachment-sitemap should only contain attachments of published posts.
What happened instead?
When creating the attachment-sitemap wordpress-seo will publish links to attachments of unpublished posts resulting in 404 errors. This is because you only check the post_status of the current item (which is inherit for all attachments) but not the post_status of the parent_post.
How can we reproduce this behavior?
Create a post-draft with attached images. The images will be added to the attachment-sitemap "?attachment_id=6254"-style even though the post is not published. In my case the images were also not reachable (for a non-admin).
The solution
I proposed a solution in pull-request #4240 but @Rarst wanted to look into a more performant solution and maybe a more comprehensive one for the whole attachment sitemap.
Misc
While I'm here, another question: should the attachment sitemap not also contain the connected image for each attachment page?
For some context inherit status is a mess, with some other related issues. Since it is only relevant for attachments I have a vague idea to maybe break them out into separate handler class altogether. This might allow to simplify handling for "normal" post types too.