Getting an error when shortId is filled in



  • We are seeing this error: Template must contains _id, name, shortid or content attribute. And are trying to figure out why. We don't see it all the time and have been having trouble reproducing it out side our production env.

    https://github.com/jsreport/jsreport/blob/master/packages/jsreport-core/lib/worker/templates.js#L10

    We log out the short_id right before sending this request to jsreport for rendering and it logs out without issue.

    We are entering it into body.template.shortid but it is checking req.template.shortid? I'm assuming this gets converted to req.template.shortid before this point as it does show up correctly when I tested it out locally. Do you know of anyway that even if the shortId is set in req.body.template.shortid, that it would still throw this error? It doesn't seem like that should be possible.



  • Do you receive the error on the client? Or it is just logged in the server logs?
    What jsreport version do you use? What template store driver?
    Do you use jsreport docker workers extension or async reports extension?
    Something unusual you could mention?

    Could you edit the templates.js file to throw an error with more details?

      throw reporter.createError('Template must contains _id, name, shortid or content attribute; req:' + JSON.stringify(req), {
              weak: true,
              statusCode: 400
            })
    


  • Logged in the server logs.
    We are on version 4.4.0
    Template store we use mssql, blob storage we use S3 bucket.
    We are seeing this with non async call only, but not always, and we do use async as well.
    We are setup using docker but not using docker workers extension.

    Here is a snippet of what we are doing we have our own endpoints configured and we have been editing the req and forwarding it on for jsreport to handle. We saw this once we upgraded to 4.4 which was just this week. We have tried but have not seen the error or been able to recreate it out side of our production env. If I succeed in doing so eventually I will edit that error to throw more info.

    logger.info(`Retrieved Short ID ${shortid}`); // this logs with a valid shortId
    
    req.url = "/api/report";
    req.method = "post";
    req.body = {
      template: { shortid: "shortid" },
      data: {
    ... // data the template will use
      },
      options: {
        reports: { async: false },
        "reportName": name
      }
    };
    req.app.handle(req, res, next);
    


  • Hmm, I don't have a theory for this at this moment. I've tried a load test with no luck so far.
    Hopefully, you get to isolate the problem.



  • Wanted to give an update. We found the issue the client was sending the request with Content-Type=application/octet-stream and this causes that error to be thrown.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.