Hyper Open Edge Cloud

How To Debug ERP5

How To showing tips and tricks on debugging ERP5.
  • Last Update:2021-03-10
  • Version:002
  • Language:en

This HowTo includes tips and tricks on debugging ERP5.

Table of Contents

Debugging

Using log

from erp5.component.module.Log import log
log("message")

then message will be in zope event log.

Using pdb

The simplest solution is to use:

import pdb; pdb.set_trace()

Somewhere in python code. To have console attached start zope in foreground mode. With slapos, if zope is running on slappart6: for example, the commands to type in terminal would be something like this:

slapos node stop slappart6: # replace slappart6: with the partition running zope

slappart6/etc/service/zope-0-(hash)  # replace (hash) with the name of the zope service

Then zope will be running attached to this terminal, so you can interact with pdb.

Another way, in theory, could be to use   slapos node supervisorctl fg slappart6:zope-0-(hash) but this does not seem to work. 

Using test infrastructure

When investigating a problem, the best is usually to reproduce the problem in a test, so that this test can be added to the test suite to prevent regression. When running tests using "Run Live Tests" portal components, there's a "Debug" checkbox that can be used to start a debugging session on errors. This also needs the zope process to be attached to the console.

 

Notes about transactions

Zope is a multi threaded application where each thread runs a transaction with an isolated view of the databases. During debugging session with pdb, it might be required to interact with transaction system, for example after editing a python script using the web interface.

Committing changes into ZODB

import transaction
transaction.commit()

Fetching changes from ZODB

To synchronise your debug session with current Zope state you need to use such snippet:

portal._p_jar.sync()

Related Articles