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

GraphQL errors when returning files #19240

Closed
wezell opened this issue Sep 8, 2020 · 2 comments
Closed

GraphQL errors when returning files #19240

wezell opened this issue Sep 8, 2020 · 2 comments

Comments

@wezell
Copy link
Contributor

wezell commented Sep 8, 2020

Contentlet object's map should not be mutated. We accidently do this with Binary fields. Sometimes (most of the time) we expect file fields in our content object to be instances of java.io.File as we do here:

https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/model/Contentlet.java#L1182

and sometimes we set them to be Strings, like in the BinaryViewStrategy class here:
https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/strategy/BinaryViewStrategy.java#L65

We need to pick one or the other and stick with it. The BinaryViewStrategy explicitly sets binaries to Strings in the content map - basically mutating the content's map. This should be a no-no.

To see this in action:

  1. import the movies/studios/ratings bundle.
  2. In the backend list movies and open a few
  3. Then run this graphql query:
{
  MovieCollection(sortBy: "movie.title desc", limit: 10) {
    title
    studio{
      name
      logo{
        name
      }
    }
  }
}

You will get null for the logos and a message

      "message": "Internal Server Error(s) while executing query"

Logs:

09:57:33.618  ERROR error.DefaultGraphQLErrorHandler - Error executing query Exception while fetching data (/MovieCollection[9]/studio[0]/logo) : java.lang.String cannot be cast to java.io.File
java.lang.ClassCastException: java.lang.String cannot be cast to java.io.File
	at com.dotmarketing.portlets.contentlet.model.Contentlet.getBinary(Contentlet.java:1182) ~[classes/:?]
	at com.dotmarketing.portlets.contentlet.transform.strategy.BinaryViewStrategy.transform(BinaryViewStrategy.java:83) ~[classes/:?]
	at com.dotmarketing.portlets.contentlet.transform.strategy.BinaryViewStrategy.transform(BinaryViewStrategy.java:60) ~[classes/:?]
	at com.dotmarketing.portlets.contentlet.transform.strategy.AbstractTransformStrategy.apply(AbstractTransformStrategy.java:95) ~[classes/:?]
	at com.dotmarketing.portlets.contentlet.transform.DotContentletTransformerImpl.lambda$3(DotContentletTransformerImpl.java:95) ~[classes/:?]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_162]
	at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[?:1.8.0_162]
@dsilvam
Copy link
Contributor

dsilvam commented Sep 9, 2020

PR: #19242

@bryanboza
Copy link
Member

Fixed, tested with the provided bundle on release-5.3.8 // Postgres // FF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants