jsreport / jsreport-pdf-utils

jsreport extension providing pdf operations like merge or concatenation
MIT License
8 stars 4 forks source link

Changes made in execution of the pdf-utils remain even after the rendering of the report. #17

Closed dfiorentin closed 5 years ago

dfiorentin commented 5 years ago

The problem is the following: I need a way to add/remove some reports dynamically using pdf-utils, based on some computation on data (chrome recipe). For example, if in datas that came from an application there's a particular option, i need to add a report on prepend/append.

I've tried a solution involving a script on beforeRenderer, that change req.template.pdfOperations based on data:

function beforeRender (req, res, done) {
...
var operations = [];
if(<something>) {
//Add a report
        operations.push({
            "type": "append",
            "templateShortid": "xxxxx",
            "mergeToFront": false,
            "renderForEveryPage": false,
            "mergeWholeDocument": false
        });
    }
...
req.template.pdfOperations = operations;

done();

I've try to replicate on the playground (run the template merging test) https://playground.jsreport.net/w/dfiorentin/KuHWJU0z and it works correctly here. However, if I use the same on my configuration, the utils has been overwritten.

The first time you run the report, everything works as expected. In the following ones, however, it seems that it has memory of previous executions, producing unexpected results. If I refresh the page, I notice that the report now has in its parameters in the pdf-utils section the reports added through the script.(initially it has nothing).

In fact, If I run it locally in debug mode, I notice that req.template.pdfOperations is not empty.

Another strange fact is related to the order in which I go to add reports to the pdf utils: if in the first execution I only add one report and in the second I add 2, it works correctly. If in the first execution I add 2 reports and in the next one I represent only one, it renders that report twice. It almost seems that several reports can be added in append/merge, but I can't remove them.

My package list is the following:

{
  "name": "jsreport-server",
  "dependencies": {
    "jsreport": "2.3.0",
    "jsreport-chrome-pdf": "1.2.2",
    "jsreport-pdf-utils": "1.2.1",
    "jsreport-studio": "2.3.3"
  },
  "main": "server.js"
}

So this should be the last jsreportversion (i've done another npm install again just now).

About my jsreport configuration, I've tried to remove all of template's options in search of the problem, but I still have the issue, even with the following configuration:

{
  "certificate": {
    "key": "certificates/jsreport.net.key",
    "cert": "certificates/jsreport.net.cert"
  },
  "httpPort": 3001,
  "license-key": "----",
  "store": {
    "provider": "fs"
  },
  "extensions": {
    "authentication": {
      "cookieSession": {
        "secret": "---"
      },
      "admin": {
        "username": "---",
        "password": "---"
      }
    }
  }
}

Some new information that could help: we save report in fileSystem and not in DB, can be related to this the problem? Another thing: I noticed that if I run the report, reload the page and reopen the template, the report has the parameters of the util modified. If I turn off and on jsreport again, the configuration of the template returns to the original one. Is there any caching system that creates conflict?

We will run jsreport either in local or in a docker installation.

Thank you.

bjrmatos commented 5 years ago

thanks for the description. actually my comment on the forum was asking if you can put your project in a github repository so we can test the same thing that you have on your local too. but i guess it is fine, because we have the entities in the playground and also your package.json and your config, so i guess we can replicate with just that.

we will give a look and see if we can replicate the bug. thanks

dfiorentin commented 5 years ago

I'm sorry, I just created the repository, I hope it helps! https://github.com/dfiorentin/pdfutils_merging_problem Thank you.

bjrmatos commented 5 years ago

excellent, thank you for that. now it will much easier to replicate. let's see..

dfiorentin commented 5 years ago

Any news?

bjrmatos commented 5 years ago

@dfiorentin yes, i'm looking into the problem right now, i have confirmed that the bug exists, but i'm still investigating the source of the problem..

dfiorentin commented 5 years ago

Perfect, thank you.

bjrmatos commented 5 years ago

i solved this bug, and the fix will be part of the next jsreport release.

if you want to try the fix, you would need to update a lot of extensions (because the bug was present in a package that was common dependency of other extensions)

you would need to do the following:

thanks for the bug report.