Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gatsby/Wordpress returning null on images after unpublishing #13104

Closed
HandsomeCreative opened this issue Apr 4, 2019 · 8 comments · Fixed by #13140
Closed

Gatsby/Wordpress returning null on images after unpublishing #13104

HandsomeCreative opened this issue Apr 4, 2019 · 8 comments · Fixed by #13140
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@HandsomeCreative
Copy link

HandsomeCreative commented Apr 4, 2019

Description

I'm using: Gatsby, Wordpress, and gatsby-source-wordpress, and ACF on Wordpress for my custom data.

The issue I'm encountering is this: when a post is unpublished (from being published to a draft), and then re-published, the images (or almost all of them) become null.

Example GraphQL being used:

        main_images {
          product_code
          image {
            title
            localFile {
              childImageSharp {
                fluid(maxWidth: 1200) {
                  ...GatsbyImageSharpFluid_withWebp
                }
                fixed(width: 100) {
                  ...GatsbyImageSharpFixed
                }
              }
            }
          }
        }

In the instance of this GraphQL field, the issue I'm having is that localFile will be null. The title in that query comes back fine, however.

Furthermore, it also seems that the wordpress API response is correct. It seems highly possible its a bug in gatsby-source-wordpress, caching related?

Help or advice would be much appreciated.

Other notes:

  • Unpublishing it and republishing it again (or several times) doesn't fix it
  • The only way I know to fix this issue is to delete all the images on the post and re-add them.
  • The images have return type of Image URL (changing it has no effect on the issue)

Steps to reproduce

Clear steps describing how to reproduce the issue. Please please please link to a demo project if possible, this makes your issue much easier to diagnose (seriously).

Expected result

What should happen?

Actual result

What happened.

Environment

System:
OS: Windows 10
CPU: (16) x64 AMD Ryzen 7 2700 Eight-Core Processor
Binaries:
Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1.0
npmPackages:
gatsby: ^2.1.0 => 2.2.6
gatsby-image: ^2.0.20 => 2.0.25
gatsby-plugin-manifest: ^2.0.9 => 2.0.12
gatsby-plugin-netlify-cache: ^1.1.0 => 1.1.0
gatsby-plugin-offline: ^2.0.16 => 2.0.20
gatsby-plugin-react-helmet: ^3.0.2 => 3.0.5
gatsby-plugin-react-svg: ^2.0.0 => 2.0.0
gatsby-plugin-sharp: ^2.0.14 => 2.0.16
gatsby-plugin-sitemap: ^2.0.11 => 2.0.11
gatsby-plugin-styled-components: ^3.0.4 => 3.0.4
gatsby-source-filesystem: ^2.0.8 => 2.0.12
gatsby-source-wordpress: ^3.0.25 => 3.0.25
gatsby-transformer-sharp: ^2.1.8 => 2.1.9

@pieh
Copy link
Contributor

pieh commented Apr 4, 2019

I'm gonna need to check this out to see if I can reproduce it, it does seem very weird

@pieh
Copy link
Contributor

pieh commented Apr 4, 2019

Seems like I get same effect with minimal repro

@pieh pieh added status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby labels Apr 4, 2019
@HandsomeCreative
Copy link
Author

Thanks for checking it out, I think it may be the thing listed here, doing what it said fixed the issue: https://www.gatsbyjs.org/packages/gatsby-source-wordpress/#graphql-error---unknown-field-localfile-on-type-image-field

If that definitely is the case, is there maybe a fix the gatsby plugin can implement to fix it, or is something only fixable on the wordpress side? If so, I wonder if a wordpress plugin could be made to automatically do this.

@pieh
Copy link
Contributor

pieh commented Apr 4, 2019

Yes, this is also one of the ways to workaround this. This happens because when you unpublish post that reference images - those images get "unpublished" too (and therefore removed from data store, but cache is not getting updated about and it tries to use non-existent nodes).

I just opened Pull Request with change that fixes it ( #13140 )

@HandsomeCreative
Copy link
Author

Cool! I will test your PR if you'd like, not sure how to install your PR though (the mono repo has me a bit confused on how to do that).

I had thought it couldn't be solved like this because I entirely nuked .cache and public a couple times when running into this, and that didn't fix it 🤔

@sidharthachatterjee
Copy link
Contributor

Fixed and published in [email protected] thanks to @pieh 🎉

@pieh
Copy link
Contributor

pieh commented Apr 5, 2019

I had thought it couldn't be solved like this because I entirely nuked .cache and public a couple times when running into this, and that didn't fix it 🤔

This is really weird. We can't solve fact that wordpress "hides" image from being listed in image list response when you unpublish post (unless you remove post_parent thingie as via troubleshooting suggestion). But once post is published back, image should be visible.

@pieh
Copy link
Contributor

pieh commented Apr 5, 2019

I guess this can happen when you upload image to one post, unpublish that and then try to use same image in another post - at that point there is nothing we can do to fix it. Maybe there is some wordpress plugin that automatically could remove post_parent - but that's on wordpress side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
3 participants