Try ERPNext Buy Support Partners Foundation

Problem Upgrading to v12

Hello everyone, I am attempting an upgrade from a v10 -> v12 and I get this error. I am doing this in our dev environment which is a replica of prod. I have looked around the patch itself. There is no table called Asset Settings that I can find in the database to patch. Is this a missing column? How can I find out what table this is on? I also tried skipping the update. And I get the
image

even though the bench fully clears.

I have attached the following trace. Which is what I get.

 Executing erpnext.patches.v12_0.set_cwip_and_delete_asset_settings in site1.local (_1bd3e0294da19198)
    Traceback (most recent call last):
      File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
        main()
      File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
        click.Group(commands=commands)(prog_name='bench')
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 764, in __call__
        return self.main(*args, **kwargs)
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 717, in main
        rv = self.invoke(ctx)
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 956, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 555, in invoke
        return callback(*args, **kwargs)
      File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
        return f(get_current_context(), *args, **kwargs)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
        ret = f(frappe._dict(ctx.obj), *args, **kwargs)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 253, in migrate
        migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 48, in migrate
        frappe.modules.patch_handler.run_all(skip_failing)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 41, in run_all
        run_patch(patch)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 30, in run_patch
        if not run_single(patchmodule = patch):
      File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 71, in run_single
        return execute_patch(patchmodule, method, methodargs)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 91, in execute_patch
        frappe.get_attr(patchmodule.split()[0] + ".execute")()
      File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v12_0/set_cwip_and_delete_asset_settings.py", line 12, in execute
        cwip_value = frappe.db.get_single_value("Asset Settings", "disable_cwip_accounting")
      File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 559, in get_single_value
        frappe.throw(_('Invalid field name: {0}').format(frappe.bold(fieldname)), self.InvalidColumnName)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 377, in throw
        msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 356, in msgprint
        _raise_exception()
      File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 316, in _raise_exception
        raise raise_exception(msg)
    frappe.database.database.InvalidColumnName: Invalid field name: <b>disable_cwip_accounting</b>

I would prefer upgrading to v11 first and then to v12. May be the database upgrades are fully managed that way.

Try that as well its having the same issue.

I am adding the patch content as well

from __future__ import unicode_literals
import frappe
from frappe.utils import cint


def execute():
        '''Get 'Disable CWIP Accounting value' from Asset Settings, set it in 'Enable Capital Work in Progress Accounting'$        in Company, delete Asset Settings '''

        if frappe.db.exists("DocType", "Asset Settings"):
                frappe.reload_doctype("Asset Category")
                cwip_value = frappe.db.get_single_value("Asset Settings", "disable_cwip_accounting")

                frappe.db.sql("""UPDATE `tabAsset Category` SET enable_cwip_accounting = %s""", cint(cwip_value))

                frappe.db.sql("""DELETE FROM `tabSingles` where doctype = 'Asset Settings'""")
                frappe.delete_doc_if_exists("DocType", "Asset Settings")

Try ‘bench migrate’ once … it should update the database schema …

I have tried, bench migrate, bench update --reset, I have tried to skip the patch by “#” in the patch.txt. I have bench update --patch, no matter what I run through it the error returns the same. Typically this means a column is missing from a table. I just do not know what table this. I have added the “disable_cwip_accounting” column to every table in Asset to troubleshoot it. But so far none have work. Even if it skips the patch and the bench finishes its migration I then get the 503.

The patch checks frappe.db.exists for the Asset Settings and then tries to access column name. That means you should already have ‘tabAsset Settings’ table in the database. Trying adding the column there.

Which is what I would have thought.


But there isnt one! let me try to create a table and add that column to it.

OK. I got a chance to review the patch in detail. The frappe.db.exists is checking in tabDocType for Asset Settings has been defined in this instance. In your case it turns out to be true but then you don’t seem to have it defined, As such your tabSingles does not have any entry for Asset Settings. Which ideally should not be the case.

However, You can edit this line in the patch

cwip_value = frappe.db.get_single_value("Asset Settings", "disable_cwip_accounting")

with (it is the default value)

cwip_value = "0"

Hope it helps.

1 Like

This is happening because the schema of table are not updated and before it they are doing patch update.
You can comment out the function in patch and let the schema update first after the schema get updated again do patch update

I am testing out this solution. It did bypass the setting, I ran a bench migrate to get it to compile. Then a bench update again to get it to build. And this seems to have worked! Thank you so much!