Openerp debugging

Submitted by sean on Wed, 05/19/2010 - 16:48


Compact dev overview:

Official docs:

The forums...



  • Pdb is the integrated python debugged. Instead of using /etc/init.d/openerp-server, start openerp with --debug to the console. e.g.
    su postgres -c "/opt/openerp.bzr/server/bin/  --debug --config=/etc/openerp-server.cfg"
    It drops to the debug prompt if there is an exception.
    There one can single step, list recent lines (l), print variables (pp) etc..
  • do a tail on the openerp server and postgres logs
    tail -f /var/log/openerp/server.log
    tail /var/log/postgresql/postgresql-8.*-main.log

Code debugging

  • Start the server with an appropriate debug level enabled:
    --log-level=LOG_LEVEL ['info', 'debug_rpc', 'warn', 'critical', 'error','debug', 'notset']
  • Code syntax errors are difficult to understand from the server logs, to start a local python instance and load the module you're test by hand, to see if errors are reported. Adapt /openerp to the path where the openerp server sources are.

import sys
from osv import osv, fields

  • Create breakpoints at key sections, step strough examining variables and pasting in code to try it out.

import pdb

  • Use lots of prints and perhaps pretty print

import pprint

pp = pprint.PrettyPrinter(indent=2)


  • Perhaps create you own debug logging function

import netsvc
logger = netsvc.Logger()
if debuglog==1:
  import logging
  logging.getLogger().setLevel(logging.DEBUG)            # DEBUG INFO(default) WARNING ERROR CRITICAL

class logit(object):
    Log msg to the Openerp server log, with a standard prefix to identify the class,
    the default level is INFO but can be set as the second parameter.
    Set debuglog=1 at a higher level to enable module/function tracing
    def __init__(self, msg='', level=netsvc.LOG_INFO):
        global debuglog
        prefix=self.__class__.__name__ +': '
        if (debuglog==1) or (level==netsvc.LOG_DEBUG):    # add caller module/method
            import inspect
            prefix=inspect.stack()[1][1] +' ' +inspect.stack()[1][3] +'() ' +prefix
        #print(prefix + msg)
        logger.notifyChannel("", level, prefix + msg)


I'm still a vim + pdb fan myself, but an having a look at IDEs...

If going for an IDE, Aptana+ pydev is better than eclipse+pydev: easier to getup & going.
Download the standalone version (not deb packages) from, then install the pydev extensions from the Help> Install Aptana features dialog.

I didn't find a way for it to trace in real time though openserp server code, objects modules, and help me understand how certain features work..

Vim has great syntax highlighting that catches mayn xml and py errors.

Komodo IDE: is a commercial one, not tested though....

Pydev notes


F9: run, F11 debug run
 Step in: F5, over: F6, Continue: F8
 Ctrl-G: comment wrap
 Must test more of these:
    * Breakpoints (with optional condition)
    * Stack view showing multiple threads
    * Locals and Globals variable display
    * Expressions display
    * Temporary display for selection: Ctrl+Shift+D
    * Hover showing the selected expression evaluation

More vim

Remember your current position:
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    | exe "normal g'\"" | endif

Xmlint (in package libxml2-utils) can check xml for you.
 autocmd BufWrite *xml exe ":silent %!xmllint --format --recover - 2>/dev/null"

For openerp RML report, it can also help:
xmllint --relaxng import_xml.rng <your rml file>

Further reading: