Home › Curriculum › Technical Foundations › Debugging Python: tracebacks, logging and pdb
Python for Odoo · 14 min · Python 3.12 + OdooDebugging Python: tracebacks, logging and pdb
Reading tracebacks bottom-up, using the logger, the Odoo shell and the debugger.
In this lesson
- Reading tracebacks
- Logging properly
- odoo-bin shell and pdb
Key points
- Read tracebacks bottom-up; find the first frame in your code
- _logger = logging.getLogger(__name__); log levels; --log-handler
- odoo-bin shell -d db for live inspection; rollback by default
- breakpoint(): n, s, c, p, l, q; never commit breakpoints
Real-world example
A scheduled sync failed every night with no visible error. Raising the module's logger to DEBUG with --log-handler showed a timeout on page 37 of the API. The fix (pagination with retries) took an hour once the log told the story.
Questions and answers
How do you show only your module's debug logs?
--log-handler=odoo.addons.<module>:DEBUG
What should you do before leaving the shell after experiments?
env.cr.rollback() unless you deliberately want to commit.