frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
21.82k stars 7.33k forks source link

Fresh Custom Apps Based Setup Fails #40128

Closed robertdown closed 8 months ago

robertdown commented 8 months ago

Description of the issue

Here is apps.json

[                                               
  {                                             
    "url": "https://github.com/frappe/erpnext", 
    "branch": "version-14"                      
  },                                            
  {                                             
    "url": "https://github.com/frappe/hrms",    
    "branch": "version-14"                      
  },                                            
  {                                             
    "url": "https://github.com/frappe/payments",
    "branch": "version-14"                      
  }                                             
]

I create the image by running the following commands:

export APPS_JSON_BASE64=$(base64 -w 0 ./apps.json)
docker build --build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 --tag=test/erp:14 --file=images/custom/Containerfile .
docker compose --project-name erptest \
--env-file ~/gitops/erptext.env \
-f compose.yaml \
-f overrides/compose.redis.yaml \
-f overrides/compose.noproxy.yaml \
-f overrides/compose.mariadb.yaml config > ~/gitops/erptest.yaml
docker compose --project-name erptest --env-file ~/gitops/erptest.env -f ~/gitops/erptest.yaml up -d

I also ensure the base compose file is pointing to test/erp and not the default frappe

I then drop into the backend via docker exec and run this:

# Confirm the expected apps are here, they are
bench version
bench new-site --mariadb-root-password changethis --admin-password changethis erptest.internal
bench --site erptest.internal install-app erpnext

I end up with this error

Installing erpnext...
Updating DocTypes for erpnext       : [                                        ] 2%An error occurred while installing erpnext: Module import failed for Sales Taxes and Charges Template, the DocType you're trying to open might be deleted.<br> Error: cannot import name 'Round' from 'frappe.query_builder.functions' (/home/frappe/frappe-bench/apps/frappe/frappe/query_builder/functions.py)
Traceback (most recent call last):
  File "apps/frappe/frappe/modules/utils.py", line 245, in load_doctype_module
    doctype_python_modules[key] = frappe.get_module(module_name)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 1327, in get_module
    return importlib.import_module(modulename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "apps/erpnext/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py", line 10, in <module>
    from erpnext.controllers.accounts_controller import (
  File "apps/erpnext/erpnext/controllers/accounts_controller.py", line 38, in <module>
    from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center
  File "apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in <module>
    from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
  File "apps/erpnext/erpnext/accounts/doctype/budget/budget.py", line 13, in <module>
    from erpnext.accounts.utils import get_fiscal_year
  File "apps/erpnext/erpnext/accounts/utils.py", line 13, in <module>
    from frappe.query_builder.functions import Round, Sum
ImportError: cannot import name 'Round' from 'frappe.query_builder.functions' (apps/frappe/frappe/query_builder/functions.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "apps/frappe/frappe/commands/site.py", line 416, in install_app
    _install_app(app, verbose=context.verbose, force=force)
  File "apps/frappe/frappe/installer.py", line 294, in install_app
    sync_for(name, force=force, reset_permissions=True)
  File "apps/frappe/frappe/model/sync.py", line 81, in sync_for
    import_file_by_path(
  File "apps/frappe/frappe/modules/import_file.py", line 145, in import_file_by_path
    import_doc(
  File "apps/frappe/frappe/modules/import_file.py", line 242, in import_doc
    doc.insert()
  File "apps/frappe/frappe/model/document.py", line 285, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1082, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 914, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 1264, in composer
    return composed(self, method, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 1246, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 911, in fn
    return method_object(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 408, in on_update
    self.run_module_method("on_doctype_update")
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 493, in run_module_method
    module = load_doctype_module(self.name, self.module)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/modules/utils.py", line 249, in load_doctype_module
    raise ImportError(msg) from e
ImportError: Module import failed for Sales Taxes and Charges Template, the DocType you're trying to open might be deleted.<br> Error: cannot import name 'Round' from 'frappe.query_builder.functions' (apps/frappe/frappe/query_builder/functions.py)

Context information (for bug reports)

Output of bench version

bench version
erpnext 14.63.3
frappe 14.32.1
hrms 14.22.0
payments 0.0.1

Additional information

OS version / distribution, Frappe install method, etc.

ankush commented 8 months ago

https://github.com/frappe/frappe/blob/52ebc4f7d0b9153d9430b9b3ac83f090158a05c2/frappe/query_builder/functions.py#L44

The function seems to exist (since ~9 months) :thinking:

robertdown commented 8 months ago

Going to close this - I spun up a fresh VM and attempted to recreate and was unable to. I'm thinking something with the underlying setup was causing an issue that couldn't be resolved by just starting with a new docker compose up