Erpnext patching & updates

is there a standardised procedure for keeping erpnext software patched and up to date - for instance on a linux system i would update all repositories and then upgrade everything - this can generally be accomplished with a couple of commands. I ask the question because I have an instance at v13.24.0 and another instance at v13.29.0 and i would like to keep everything up to date and consistant (and importantly understand how that is achieved and how ive managed to get distinct code levels without trying!)

The short answer is you run this command:

bench update

Now hereā€™s the longer explanation. This command does a lot of small tasks. Tasks you ā€œcouldā€ do yourself manually, in your console. Thereā€™s no magic here: Bench is just saving you some keystrokes. Here is the general idea of what happens when you run that command.

For each App you have installed (Frappe, ERPNext, others):

  1. A 'git pull' command is executed in your Appā€™s root directory. Your local code and files are updated, based on whatever is currently in GitHub/GitLab for your git ā€˜branchā€™.
  2. Python packages are installed/updated based on the new contents of the Appā€™s 'requirements.txt' file. Updates are (mostly) made from PyPi.org repositories.
  3. Node.js packages are installed/updated, based on the new contents of the Appā€™s 'package.json' files. (using the yarn package manager)
  4. JS and CSS assets are ā€œrolled upā€ (minified, concatenated, bundled) to create new asset files.
  5. Based on DocType schema definitions inside .json text files, your MariaDB SQL databaseā€™s schema is updated (tables, columns, indexes)
  6. If it exists, ā€œpatch codeā€ is run. By ā€œpatch codeā€, I mean scripts that update your SQL databaseā€™s existing records, based on the new schema and requirements from step 5.

If everything goes well, then thatā€™s it. Youā€™re on the newest minor and patch version.

To upgrade a major version (e.g. v13 ā†’ v14), we used to type this command:

bench update --upgrade

Does this command still work today? I have no idea. The official documentation never explains how to upgrade. :man_facepalming:

I tried to answer this for myself, by running bench update --help. However, the '--upgrade' flag is gone. Thereā€™s a --force flag, but Iā€™m reluctant to say thatā€™s the answer (in most CLI Iā€™ve seen, --force is a suffix usually reserved for doing something potentially breaking.)

So who knows.

Hopefully this information helps, @alpresidente. I stopped using ā€˜bench updateā€™ years ago, so Iā€™m not an expert. Hopefully someone else can chime in about the major version upgrades.

6 Likes

Major version upgrades are done through github branches, so the command would be bench switch-to-branch version-1*. Without doing that, your site will always stay on the same major version but accept minor version updates.

1 Like

with a few repeats of ā€œbench updateā€ and some reboots ive been able to get the code levels the same on 2 instances. I do get the following errors although ā€œbench setup requirementsā€ seems to run without fault - both instances now at:
ERPNext: v13.31.1 (version-13)
Frappe Framework: v13.30.0 (version-13)
ā€¦which i think is current

UNRESOLVED_IMPORT : ā€˜vue/dist/vue.jsā€™ is imported by ā€¦/erpnext/erpnext/public/js/hub/vue-plugins.js, but could not be resolved ā€“ treating it as an external dependency
Cannot find some dependencies. You may have to run ā€œbench setup requirementsā€ to install them.

UNRESOLVED_IMPORT : ā€˜vue/dist/vue.jsā€™ is imported by ā€¦/erpnext/erpnext/public/js/hub/marketplace.js, but could not be resolved ā€“ treating it as an external dependency
Cannot find some dependencies. You may have to run ā€œbench setup requirementsā€ to install them.

MISSING_GLOBAL_NAME : No name was provided for external module ā€˜vue/dist/vue.jsā€™ in output.globals ā€“ guessing ā€˜Vueā€™
:heavy_check_mark: Built js/marketplace.min.js
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
:heavy_check_mark: Built css/erpnext-web.css
:heavy_check_mark: Built css/marketplace.css
:heavy_check_mark: Built css-rtl/marketplace.css
:heavy_check_mark: Built css-rtl/erpnext-web.css
:heavy_check_mark: Built css/erpnext.css
:heavy_check_mark: Built css-rtl/erpnext.css

@brian_pond as always, your posts are fairly useful for us all. Hopefully you can share your experience on this regard.

As you stated,

bench update

does a lot of other smaller tasks, in a particular sequence of actions. It patches, updates database, modifies a lot of things. Itā€™s never clear what the sequence is.

Iā€™m on version-13 branch, frappe on 13.51.3, erpnext on 13.49.10, and with my own Custom Apps, I canā€™t do bench update. It says:

ModuleNotFoundError: No module named ā€˜frappe.custom.doctype.diy_icon_type.diy_icon_typeā€™

diy_icon_type is a Custom DocType that I created. Plus a few others new DocTypes.

I also monkey patched apps/frappe, and changed some core .js files.

The new DocTypes will create new .json files, my new Custom Apps, some modified core .js files, and various other things.

How should I update frappe and erpnext? What are the exact steps so that I can have a reference?

Should I merge my own branch of Custom Apps and revised code to the existing branch (version-13) before I do a PULL?

What I tried so far is:

  • go into apps/frappe
  • fix .git/config issues
  • git checkout version-13
  • git pull --rebase

Success. Updated to 13.57.1.

  • go into apps/erpnext
  • fix .git/config issues
  • git checkout version-13
  • git pull -rebase

Success. Updated to 13.51.6.

Then what?

Should I run:

  1. bench update --patch?
  2. bench migrate?
  3. bench build?
  4. bench start

in that sequence?

PS: I studied your post on Git setup for professional frappe erpnext and custom app development
Guidance to work with Forks on Github for ERPNext only - #7 by brian_pond

I very rarely use hooks.py or monkey patching (I create forks instead). So may not be able to offer the best advice.

The 'ModuleNotFoundError' is sometimes a hint that one of these is happening:

  • Circular Reference problems.
  • hooks.py is not being loaded (Iā€™ve seen this happen occasionally when running code via 'bench execute')
  • References to modules/functions are being called before the namespaces are fully loaded.

If the frappe module now requires code from your custom module? This could be a kind of circular reference problem:

  • Frappe needs your moduleā€™s code.
  • Your module needs Frappeā€™s code.

Itā€™s possible that neither can fully import without the other, so you get ā€œstuckā€.

If you suspect Circular References are in play, you could try moving your 'import' statements for diy_icon_type. Instead of at the top of the module, place them inside the function(s) that require it.

Example:

# Original
from my_module.my_doctype import foo
...
def myfunc():
    foo.do_something_helpful()
# Altered

def myfunc():
    from my_module.my_doctype import foo
    foo.do_something_helpful()

Thatā€™s the first thing that comes to my mind. When it comes to hooks and monkey patches, Iā€™m not sure precisely where/when they are invoked during bench update. :thinking:

1 Like