Rebuild Broken Nested Set

Continuing the discussion from 404 not found after domain change:

No, we didnt add anything directly in the DB, just a fresh new install on Centos 7. Still do not work, we did as root:

$ bench frappe --ipython
Python 2.7.5 (default, Jun 17 2014, 18:11:42) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from frappe.utils.nestedset import rebuild_tree

In [2]: rebuild_tree("Item Group", "parent_item_group")

In [3]: frappe.db.commit()

In [4]: exit

$

Could be an error relating to Shopping Cart too. Unfortunately we have not tested it enough. Can you dig further?

OK, we will give you all the errors we are finding but please tell us how to debug further: when we log in to the desk we see in the console:

GET http://erpnext.ourdomain.com/assets/css/bootstrap.css.map 404 (Not Found) desk:28
Cleared App Cache. frappe.min.js:151
Cleared localstorage frappe.min.js:152
POST http://erpnext.ourdomain.com/ net::ERR_CONTENT_LENGTH_MISMATCH jquery.min.js:4l.cors.a.crossDomain.send jquery.min.js:4o.extend.ajax jquery.min.js:4frappe.request.call frappe.min.js:299frappe.call frappe.min.js:295frappe.Application.Class.extend.load_startup frappe.min.js:341frappe.Application.Class.extend.init frappe.min.js:341Class frappe.min.js:148(anonymous function) frappe.min.js:341j jquery.min.js:2k.fireWith jquery.min.js:2o.extend.ready jquery.min.js:2I

In /user, we receive a server error in the HTML:

Oops, a server error has occured
Traceback (innermost last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 23, in render
    data = render_page(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 105, in render_page
    return build(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 114, in build
    return build_method(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 127, in build_page
    context = get_context(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/context.py", line 36, in get_context
    context = build_context(context)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/context.py", line 72, in build_context
    ret = module.get_context(context)
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/templates/pages/user.py", line 14, in get_context
    party = get_lead_or_customer()
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 276, in get_lead_or_customer
    "territory": guess_territory(),
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 133, in guess_territory
    get_root_of("Territory")
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/nestedset.py", line 233, in get_root_of
    t2.lft < t1.lft and t2.rgt > t1.rgt) = 0""".format(doctype, doctype))[0][0]
 IndexError: tuple index out of range

In /addresses, we get in the console:

POST http://erpnext.ourdomain.com/ 500 (INTERNAL SERVER ERROR) jquery.min.js:4l.cors.a.crossDomain.send jquery.min.js:4o.extend.ajax jquery.min.js:4$.extend.call frappe-web.min.js:72fetch_addresses VM1272:3(anonymous function) VM1272:27j jquery.min.js:2k.add jquery.min.js:2o.fn.ready jquery.min.js:2(anonymous function) VM1272:26(anonymous function) VM1272:29o.extend.globalEval jquery.min.js:2o.fn.extend.domManip jquery.min.js:3o.fn.extend.append jquery.min.js:3(anonymous function) jquery.min.js:3o.access jquery.min.js:2o.fn.extend.html jquery.min.js:3(anonymous function) frappe-web.min.js:113o.extend.each jquery.min.js:2o.fn.o.each jquery.min.js:2$.extend.render_json frappe-web.min.js:113_render frappe-web.min.js:112j jquery.min.js:2k.add jquery.min.js:2d.always jquery.min.js:2v.statusCode jquery.min.js:4x jquery.min.js:4(anonymous function) jquery.min.js:4
Traceback (innermost last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/app.py", line 49, in application
    response = frappe.handler.handle()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 89, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 531, in call
    return fn(*args, **newargs)
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/templates/pages/addresses.py", line 13, in get_addresses
    return get_address_docs()
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 288, in get_address_docs
    party = get_lead_or_customer()
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 276, in get_lead_or_customer
    "territory": guess_territory(),
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 133, in guess_territory
    get_root_of("Territory")
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/nestedset.py", line 233, in get_root_of
    t2.lft < t1.lft and t2.rgt > t1.rgt) = 0""".format(doctype, doctype))[0][0]
 IndexError: tuple index out of range

It cannot find the root Territory.

  1. Check if Territory table exists
  2. Did you rebuild the tree for Territory table? I had given you Item Group in the script by mistake.
  1. Here are the tables:
    MariaDB [site1.local]> show tables;
    ±------------------------------------------+
    | Tables_in_site1.local |
    ±------------------------------------------+
    | __Auth |
    | tabAbout Us Team Member |
    | tabAccount |
    | tabActivity Type |
    | tabAddress |
    | tabAddress Template |
    | tabApplicable Territory |
    | tabAppraisal |
    | tabAppraisal Goal |
    | tabAppraisal Template |
    | tabAppraisal Template Goal |
    | tabAttendance |
    | tabAuthorization Rule |
    | tabBOM |
    | tabBOM Explosion Item |
    | tabBOM Item |
    | tabBOM Operation |
    | tabBank Reconciliation Detail |
    | tabBatch |
    | tabBin |
    | tabBlog Category |
    | tabBlog Post |
    | tabBlogger |
    | tabBranch |
    | tabBrand |
    | tabBudget Detail |
    | tabBudget Distribution |
    | tabBudget Distribution Detail |
    | tabBulk Email |
    | tabC-Form |
    | tabC-Form Invoice Detail |
    | tabCampaign |
    | tabChart of Accounts |
    | tabComment |
    | tabCommunication |
    | tabCompany |
    | tabCompany History |
    | tabContact |
    | tabCost Center |
    | tabCountry |
    | tabCurrency |
    | tabCurrency Exchange |
    | tabCustom Field |
    | tabCustom Script |
    | tabCustomer |
    | tabCustomer Group |
    | tabCustomer Issue |
    | tabCustomize Form Field |
    | tabDeduction Type |
    | tabDefaultValue |
    | tabDelivery Note |
    | tabDelivery Note Item |
    | tabDepartment |
    | tabDesignation |
    | tabDocField |
    | tabDocPerm |
    | tabDocType |
    | tabEarning Type |
    | tabEmail Alert |
    | tabEmail Alert Recipient |
    | tabEmail Digest |
    | tabEmployee |
    | tabEmployee Education |
    | tabEmployee External Work History |
    | tabEmployee Internal Work History |
    | tabEmployee Leave Approver |
    | tabEmployment Type |
    | tabEvent |
    | tabEvent Role |
    | tabEvent User |
    | tabExpense Claim |
    | tabExpense Claim Detail |
    | tabExpense Claim Type |
    | tabFeed |
    | tabFile Data |
    | tabFiscal Year |
    | tabGL Entry |
    | tabHoliday |
    | tabHoliday List |
    | tabIndustry Type |
    | tabInstallation Note |
    | tabInstallation Note Item |
    | tabItem |
    | tabItem Customer Detail |
    | tabItem Group |
    | tabItem Price |
    | tabItem Quality Inspection Parameter |
    | tabItem Reorder |
    | tabItem Supplier |
    | tabItem Tax |
    | tabItem Website Specification |
    | tabJob Applicant |
    | tabJob Opening |
    | tabJournal Voucher |
    | tabJournal Voucher Detail |
    | tabLanded Cost Item |
    | tabLanded Cost Purchase Receipt |
    | tabLanded Cost Taxes and Charges |
    | tabLanded Cost Voucher |
    | tabLead |
    | tabLeave Allocation |
    | tabLeave Application |
    | tabLeave Block List |
    | tabLeave Block List Allow |
    | tabLeave Block List Date |
    | tabLeave Type |
    | tabLetter Head |
    | tabMaintenance Schedule |
    | tabMaintenance Schedule Detail |
    | tabMaintenance Schedule Item |
    | tabMaintenance Visit |
    | tabMaintenance Visit Purpose |
    | tabMaterial Request |
    | tabMaterial Request Item |
    | tabMode of Payment |
    | tabModule Def |
    | tabNewsletter |
    | tabNote |
    | tabNote User |
    | tabNotification Count |
    | tabOpportunity |
    | tabOpportunity Item |
    | tabPOS Setting |
    | tabPacked Item |
    | tabPacking Slip |
    | tabPacking Slip Item |
    | tabPage |
    | tabPage Role |
    | tabParty Type |
    | tabPatch Log |
    | tabPayment Reconciliation Invoice |
    | tabPayment Reconciliation Payment |
    | tabPayment Tool Detail |
    | tabPeriod Closing Voucher |
    | tabPost |
    | tabPrice List |
    | tabPricing Rule |
    | tabPrint Format |
    | tabPrint Heading |
    | tabProduction Order |
    | tabProduction Plan Item |
    | tabProduction Plan Sales Order |
    | tabProject |
    | tabProject Milestone |
    | tabProperty Setter |
    | tabPurchase Invoice |
    | tabPurchase Invoice Advance |
    | tabPurchase Invoice Item |
    | tabPurchase Order |
    | tabPurchase Order Item |
    | tabPurchase Order Item Supplied |
    | tabPurchase Receipt |
    | tabPurchase Receipt Item |
    | tabPurchase Receipt Item Supplied |
    | tabPurchase Taxes and Charges |
    | tabPurchase Taxes and Charges Master |
    | tabQuality Inspection |
    | tabQuality Inspection Reading |
    | tabQuotation |
    | tabQuotation Item |
    | tabQuotation Lost Reason |
    | tabReport |
    | tabRole |
    | tabSMS Log |
    | tabSMS Parameter |
    | tabSalary Slip |
    | tabSalary Slip Deduction |
    | tabSalary Slip Earning |
    | tabSalary Structure |
    | tabSalary Structure Deduction |
    | tabSalary Structure Earning |
    | tabSales BOM |
    | tabSales BOM Item |
    | tabSales Invoice |
    | tabSales Invoice Advance |
    | tabSales Invoice Item |
    | tabSales Order |
    | tabSales Order Item |
    | tabSales Partner |
    | tabSales Person |
    | tabSales Taxes and Charges |
    | tabSales Taxes and Charges Master |
    | tabSales Team |
    | tabScheduler Log |
    | tabSerial No |
    | tabSeries |
    | tabSessions |
    | tabShipping Rule |
    | tabShipping Rule Condition |
    | tabShopping Cart Price List |
    | tabShopping Cart Shipping Rule |
    | tabShopping Cart Taxes and Charges Master |
    | tabSingles |
    | tabStandard Reply |
    | tabStock Entry |
    | tabStock Entry Detail |
    | tabStock Ledger Entry |
    | tabStock Reconciliation |
    | tabSupplier |
    | tabSupplier Quotation |
    | tabSupplier Quotation Item |
    | tabSupplier Type |
    | tabSupport Ticket |
    | tabTag |
    | tabTarget Detail |
    | tabTask |
    | tabTerms and Conditions |
    | tabTerritory |
    | tabTime Log |
    | tabTime Log Batch |
    | tabTime Log Batch Detail |
    | tabToDo |
    | tabTop Bar Item |
    | tabUOM |
    | tabUOM Conversion Detail |
    | tabUser |
    | tabUser Vote |
    | tabUserRole |
    | tabVersion |
    | tabWarehouse |
    | tabWeb Form |
    | tabWeb Form Field |
    | tabWeb Page |
    | tabWebsite Group |
    | tabWebsite Item Group |
    | tabWebsite Route Permission |
    | tabWebsite Slideshow |
    | tabWebsite Slideshow Item |
    | tabWorkflow |
    | tabWorkflow Action |
    | tabWorkflow Document State |
    | tabWorkflow State |
    | tabWorkflow Transition |
    | tabWorkstation |
    ±------------------------------------------+
    234 rows in set (0.00 sec)

  2. I did this, but not solving, hope is correct:

    $ bench frappe --ipython
    Python 2.7.5 (default, Jun 17 2014, 18:11:42)
    Type “copyright”, “credits” or “license” for more information.

    IPython 2.3.1 – An enhanced Interactive Python.
    ? → Introduction and overview of IPython’s features.
    %quickref → Quick reference.
    help → Python’s own help system.
    object? → Details about ‘object’, use ‘object??’ for extra details.

    In [1]: from frappe.utils.nestedset import rebuild_tree

    In [2]: rebuild_tree(“Territory”, “parent_territory”)

    In [3]: frappe.db.commit()

    In [4]: exit

    $

How can we debug further? This seems to be a problem when installing in Centos 7, we just performed the script installation.

OK, we found the bug. How can it be solved?

This happens when editing the file: /etc/nginx/nginx.conf and setting the user to ‘frappe’ (our user) instead ‘nginx’. If we leave the user ‘nginx’ the desk, addresses and so on works correctly, but it results in 404 not found for pictures under /public/files, see the end of this thread:

I am facing same issue on cent os 7
i am getting “GET http://osmosis1.indictranstech.com/?doctype=Sales+Order&with_parent=1&cached_timestamp=&cmd=frappe.desk.form.load.getdoctype&_=1460004715776 net::ERR_CONTENT_LENGTH_MISMATCH”

I have replaced the nginx user to frappe in nginx.conf.

If i keep nginx user the resources are not loaded.

@gangadhar_k you can run bench setup sudoers frappe