API Request returns 400 error - Render cycle detected



  • Hi I am trying to make an API request to one of my reports. Whenever I make the request I receive the following error

    message: Render cycle detected. Template at /Intelli-Sense/Geo-Sense/Monthly/Headline/template was rendered previously in this render request (hierarchy: /Intelli-Sense/Geo-Sense/Monthly/Headline/template -> /Intelli-Sense/Geo-Sense/Monthly/Headline/template). Please verify that reporter.render is not causing cycle
    
    stack: Error: Render cycle detected. Template at /Intelli-Sense/Geo-Sense/Monthly/Headline/template was rendered previously in this render request (hierarchy: /Intelli-Sense/Geo-Sense/Monthly/Headline/template -> /Intelli-Sense/Geo-Sense/Monthly/Headline/template). Please verify that reporter.render is not causing cycle    at Object.callbackRequests.(anonymous function) (/var/www/html/jsreportapp/node_modules/script-manager/lib/worker-servers.js:250:31)    at process.<anonymous> (/var/www/html/jsreportapp/node_modules/script-manager/lib/worker-servers.js:195:30)    at process.emit (events.js:198:15)    at process.EventEmitter.emit (domain.js:481:20)    at emit (internal/child_process.js:848:12)    at processTicksAndRejections (internal/process/task_queues.js:81:17)
    

    When I make the API call before the POST request is made an OPTIONS request is made which returns 204 not sure if this helps.

    Here is the code I wrote to use the API

    $('#headline_report_now_btn').click(function() {
        var request = new XMLHttpRequest();
        request.open('POST', 'https://{url}/api/report', true);
        request.setRequestHeader('Content-Type', 'application/json');
        request.setRequestHeader('Authorization', 'Basic {token}');
        request.responseType = 'blob';
    
        request.send(JSON.stringify({
            "template": {
                "shortid": "H1xtsYmyWI"
            },
            "data": {
                "user_id": "{{ current_user['id'] }}",
            }
        }));
    
        $('#confirmation_modal').modal('show');
    });
    

    Here is my script code

    const jsreport = require('jsreport-proxy');
    const axios = require('axios');
    
    async function beforeRender(req, res) {
        if (req.context.isChildRequest) {
          return
        }
    
        var user_id;
        if(req.data.user_id > 0) {
            user_id = req.data.user_id;
        }
        else {
            user_id = 'null';
        }
    
        var nodemailer = require("nodemailer");
        var sesTransport = require('nodemailer-ses-transport');
    
        var transporter = nodemailer.createTransport(sesTransport({
            accessKeyId: "{token}",
            secretAccessKey: "{token}",
            region: 'eu-west-1',
            rateLimit: 5
        }));
    
        // Perform an API request to get the JWT token needed to verify future requests
        const API_LOGIN = await axios.get({url}, {
            headers: {
                'Authorization': 'Bearer {token}'
            }
        });
    
        // Perform an API request to get all the veue data needed for the reports
        const API_VENUES_DATA = await axios.get({url} + user_id, {
            headers: {
                'Authorization': 'Bearer ' + API_LOGIN.data.JWT
            }
        });
    
        for (let venue of API_VENUES_DATA.data) {        
            const result = await jsreport.render({ 
                template: { 
                    shortid: 'H1xtsYmyWI'
                },
                data: venue
            });
    
            // Upload and email the report
            var fileName = venue.name + '_report_' + Date.now() + '.pdf'
            fileName = fileName.replace(/ /g,"_");
    
            sendEmail(fileName, transporter, venue.emails, result);
        }
    
        async function sendEmail(fileName, transporter, emails, result) {
            emails.forEach(function(email) {
                var mail = {
                    from: "{email}",
                    to: email,
                    subject: "{subject}",
                    text: "See the attached report",
                    html: `{text}`,
                    attachments: [
                    {  
                        filename: fileName,
                        content: result.content
                    }],
                }
    
                transporter.sendMail(mail, function(error, response){
                    transporter.close();
                    if(error){
                        return done(error);
                    }
                });
            });
        }
    }
    

    Thanks for any help in advance



  • Same error is happening when I try and run the report from jsreport

    Error: Render cycle detected. Template at /Intelli-Sense/Geo-Sense/Monthly/Headline/template was rendered previously in this render request (hierarchy: /Intelli-Sense/Geo-Sense/Monthly/Headline/template -> /Intelli-Sense/Geo-Sense/Monthly/Headline/template). Please verify that reporter.render is not causing cycle
        at Object.callbackRequests.(anonymous function) (/var/www/html/jsreportapp/node_modules/script-manager/lib/worker-servers.js:250:31)
        at process.<anonymous> (/var/www/html/jsreportapp/node_modules/script-manager/lib/worker-servers.js:195:30)
        at process.emit (events.js:198:15)
        at process.EventEmitter.emit (domain.js:481:20)
        at emit (internal/child_process.js:848:12)
        at processTicksAndRejections (internal/process/task_queues.js:81:17)
    


  • I recently switched servers and had to re-download everything, I rememeber having to alter some code which allowed me to do multiple render cycles. Could you let me know where this piece of code is located? :)





  • Hi,

    would you be able to modify this example so it replicates your error?
    I think it is similar to yours but I can't make it failing on loop error.
    https://playground.jsreport.net/w/anon/bFBeNeuV

    We would love to fix this if its an actual issue.
    Thank you



  • I think I must be using an older version, this might have been fixed because for some reason I cant seem to replicate the error I was having either. I'll let you know if I do come across anything though.



  • I managed to replicate the issue, it was my fault I believe. I was attached the script to the template so it was trying to render the template twice which then caused this issue. I can't think of a reason why I need to attached the script to the template either.



  • Ah ok, that could cause it. Thank you for info.


Log in to reply
 

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