App.py Not working properly in Production

Sometimes it works, sometimes it doesn’t, and I occasionally encounter a blank screen or errors.

it happened always when i am working in app.py file here i am working in app_report.py
import frappe


def execute(filters=None):
frappe.clear_cache()
columns, data = get_columns(), get_data(filters)

return columns, data

def get_data(filters):
query = “”"
SELECT
name,select_department,emp_name,
stage_1_emp_status, stage_2_emp_status,
stage_3_emp_status, stage_4_emp_status,
stage_5_emp_status, stage_6_emp_status,
stage_7_emp_status
FROM
tabAsset Request
“”"
data = frappe.db.sql(query)
return data

def get_columns():
return [
(“ID”) + “:Link/Asset Request:100”,
(“Department”) + “:Data:100”,
(“Employee”) + “:Data:100”,
(“Reporting Person Status”) + “:Data:100”,
(“HOD Status”) + “:Data:100”,
(“GM Status”) + “:Data:100”,
(“CFO Status”) + “:Data:100”,
(“CEO Status”) + “:Data:100”,
(“CTO Status”) + “:Data:100”,
(“Store Status”) + “:Data:100”,
]

After Refresh

Hi @iamtalib13,

I think, the issue you were facing was caused by how you defined columns for your Server Script Report. You were trying to combine column labels and types together in a way that was causing errors.

I made some corrections to your code by separating the column labels, fieldnames, field types, and widths into distinct parts. This way, your report should work more reliably without errors.

Please check the syntax:

import frappe

def execute(filters=None):
    frappe.clear_cache()
    columns, data = get_columns(), get_data(filters)
    return columns, data

def get_data(filters):
    query = """
    SELECT
        name, select_department, emp_name,
        stage_1_emp_status, stage_2_emp_status,
        stage_3_emp_status, stage_4_emp_status,
        stage_5_emp_status, stage_6_emp_status,
        stage_7_emp_status
    FROM
        `tabAsset Request`
    """
    data = frappe.db.sql(query, as_dict=True)
    return data

def get_columns():
    return [
        {"label": "ID", "fieldname": "name", "fieldtype": "Link", "options": "Asset Request", "width": 100},
        {"label": "Department", "fieldname": "select_department", "fieldtype": "Data", "width": 100},
        {"label": "Employee", "fieldname": "emp_name", "fieldtype": "Data", "width": 100},
        {"label": "Reporting Person Status", "fieldname": "stage_1_emp_status", "fieldtype": "Data", "width": 100},
        {"label": "HOD Status", "fieldname": "stage_2_emp_status", "fieldtype": "Data", "width": 100},
        {"label": "GM Status", "fieldname": "stage_3_emp_status", "fieldtype": "Data", "width": 100},
        {"label": "CFO Status", "fieldname": "stage_4_emp_status", "fieldtype": "Data", "width": 100},
        {"label": "CEO Status", "fieldname": "stage_5_emp_status", "fieldtype": "Data", "width": 100},
        {"label": "CTO Status", "fieldname": "stage_6_emp_status", "fieldtype": "Data", "width": 100},
        {"label": "Store Status", "fieldname": "stage_7_emp_status", "fieldtype": "Data", "width": 100},
    ]

Please check the fieldname and table name and set it according.

I hope this helps.

Thank You!