Your SlideShare is downloading. ×
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone

4,577
views

Published on

Using real issues encountered in the wild, this session will help beginning integrators gain confidence in knowing what to do when Plone fails to behave as expected. Learn how to solve common problems …

Using real issues encountered in the wild, this session will help beginning integrators gain confidence in knowing what to do when Plone fails to behave as expected. Learn how to solve common problems like "My changes aren't taking effect" and "My Zope instance won't start," as well as how to use pdb to investigate more complex Python errors.

This talk is targeted at integrators who have some experience with Plone, but who are not confident in troubleshooting errors and other unexpected behavior. Knowledge of Python is not required, though at least a cursory familiarity with some programming language will make the talk more digestible.

Published in: Technology

1 Comment
7 Likes
Statistics
Notes
  • Its really helpful to me and for a every novice to plone. Thanks a ton. It saved my time. And my kind request is come up with much more presentation regarding customizing plone default look and feel. And how to integrate paypal with plone site.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,577
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
98
Comments
1
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone Plone Conference 2008 David Glick Web Developer ONE/Northwest
    • 2. What we're going to cover
      • 1. Preparation for debugging
      • 2. Debugging tools
      • 3. 2 case studies
      • 4. Tips & tricks
    • 3.  
    • 4.  
    • 5. Newbie programmer's reaction: Absolute terror
    • 6. Experienced programmer's reaction: Absolute terror
    • 7. Maybe it's a little bug...
    • 8. ...but who knows what's in there, really!
    • 9. What could be wrong?
      • Trivial typo
      • Logic error
      • Failure to consider certain input values
      • Faulty assumptions about the state of the system
      • Deep voodoo
    • 10. Mental preparation
    • 11. Remember: You are in control.
    • 12. Remember: You are not alone.
    • 13. Use the source, Luke.
    • 14. Getting ready...
    • 15. Don't use debugging tools in production.
      • Security
      • Performance
    • 16. Run zope in foreground mode.
      • Buildout:
      • $ bin/instance fg
      • Pre-buildout:
      • $ zopectl fg
    • 17. Turn on verbose security.
      • Buildout:
      • in buildout.cfg, [instance] section:
      • verbose-security on
      • Pre-buildout:
      • in zope.conf:
      • verbose-security on
      • security-policy-implementation python
    • 18. Stop ignoring errors in /error_log
    • 19. Debugging tools
    • 20. 1. What is that thing?
    • 21.
      • Firebug (Firefox)
      • http://tinyurl.com/2z4tvg
      • IE Web Developer Toolbar (IE) http://tinyurl.com/iedevtoolbar
      • WebKit (Safari) http://webkit.org
      • Google Chrome inspector
      Investigating HTML, CSS, and Javascript >
    • 22. Investigating Plone viewlets and portlets
      • plone.app.gloworm http://tinyurl.com/gloworm
    • 23. Investigating the current page context
      • Products.Clouseau http://tinyurl.com/clouseau
    • 24. 2. What code controls this?
    • 25. Seek and ye shall find!
      • Grep
      • Multi-file search and replace feature in editor of choice
      • Code indexers (etags, glimpse)
    • 26. Where is the code?
      • From a filesystem page template:
      • <tal:block tal:replace=”python:obj.__class__”/>
      • (gives you the dotted path of module + class of obj)
      • From any page template:
      • <tal:block tal:replace=”nocall:obj”/>
      • (gives you the class name of obj)
    • 27. collective.recipe.omelette
      • Before :
      • After:
      http://tinyurl.com/collective-omelette
    • 28. 3. What's that code doing?
    • 29. Logging
      • context.plone_log(my_var)
      • Output will show up on console
      • Useful for when some code is being run repeatedly and you want to make sure it's operating on the correct values
    • 30. pdb: the Python debugger
    • 31. pdb: the Python debugger
      • Trigger with:
      • import pdb; pdb.set_trace()
      • Don't forget to remove the set_trace!
    • 32. 4. What's Zope doing right now?
      • DebugInfo page (built in): /ControlPanel/DebugInfo/manage_main in ZMI
      • DeadlockDebugger product http://tinyurl.com/deadlockdebugger
    • 33. 5. Why is this so slow ?
      • YSlow – frontend performance
      • http://developer.yahoo.com/yslow/
      • PTProfiler – page templates
      • http://plone.org/products/ptprofiler
      • ZopeProfiler – Python calls
      • http://pypi.python.org/pypi/Products.ZopeProfiler
    • 34. What does it look like in real life?
      • Case #1:
      • plone_newbie4022's Quick Installer problem
      • (from #plone, 2008-09-08)
    • 35. Reading a traceback module Line # method More recent
      • Snapshot of what code is executing
      • Doesn't include the values
    • 36. Reading a traceback (cont'd) For page template expressions Template file location The actual TAL expression that was called Location of expression within the template The actual Error message! Bonus (but irrelevant) error The Error happened here!
    • 37. Common Python exceptions
      • AttributeError
        • e.g. obj.nonexistent_attribute
      • ImportError
        • e.g. import nonexistent_module
      • IndexError
        • e.g. my_list[42] , if my_list doesn't have >=43 elements
    • 38. Common Python exceptions
      • KeyError
        • e.g. my_dict['nonexistent_key']
      • TypeError
        • e.g. foo = ('tuple',) + 'string'
      • ValueError
        • e.g. int('string')
    • 39. Common Zope exceptions
      • Unauthorized
      • NotFound
      • Redirect
      • TraversalError
      • ComponentLookupError – failed zope 3 lookup
      • ConflictError – ZODB conflict
    • 40. Lessons from Case #1
    • 41.
      • The problem is sometimes (usually?) not where you think the problem is.
    • 42.
      • Think carefully about both:
        • What the code is doing
        • What the state is of the objects in your ZODB
    • 43.
      • Often you don't have to change any code to fix a bug, once you understand what is going on.
    • 44. What does it look like in real life?
      • Case #2:
      • some (only somewhat) contrived
      • catalog trouble
    • 45. plone.reload
      • Reload Python code without restarting Zope.
      • Just go to /@@reload.
    • 46. pdb commands
      • l / list: print the code. l 42 == list line #42
      • w / where: print a traceback
      • n / next: run the next command
      • s / step: enter a method that is being called
      • r / return: execute until the current method completes
      • c / continue: continue execution indefinitely (end pdb session)
    • 47. advanced pdb commands
      • b / breakpoint: b 42 == set a breakpoint on line 42
      • cl / clear: cl 1 == remove breakpoint #1
      • j / jump: j 42 == jump to line 42
      • u / up: move up in the call stack
      • d / down: move down in the call stack
      • Full pdb docs: http://www.python.org/doc/2.5.2/lib/module-pdb.html
    • 48. pdb idioms
      • pp obj – pretty-print an object
      • dir(obj) – list an object's attributes and methods
      • obj.__dict__ -- list an object's data attributes
      • obj.__doc__ -- print an object's docstring
      • args – list the arguments passed to the current method
      • retval – print the value that will be returned from the current method
      • !expr – force expr to be treated as a Python expression rather than a pdb command
    • 49. Lessons from Case #2
    • 50.
      • If you don't have a traceback, finding the source of misbehavior can be hard . Be persistent.*
      • * Bad Zope pun not intended.
    • 51.
      • Try the most obvious things first. (Assume there's a bug in your own code, rather than in Zope/Plone.)
    • 52. Tips and Tricks
    • 53. PDBDebugMode product
      • Automatically get a pdb whenever there is a python exception
      • Invoke a pdb on any context via /@@pdb view
      • Invoke a pdb on anything via /path/to/anything?pdb_runcall=1
    • 54. Debugging python scripts
      • Use the zdb product http://www.simplistix.co.uk/software/zope/zdb
        • from Products.zdb import set_trace; set_trace()
        • Ensures that you can (l)ist the code of the Python script
        • Doesn't work for form controller Python scripts (.cpy) though
      • When stepping into calls in restricted python, you will first enter guarded_getattr, which you can (r)eturn out of and then the (n)ext call will be the one you want
    • 55. Tab key auto-completion in pdb
      • Add the following to ~/.pdbrc:
      • import rlcompleter
      • pdb.Pdb.complete = rlcompleter.Completer(locals()).complete
    • 56. Why aren't my changes coming alive?
      • template, image & stylesheet customizations:
        • put CSS, Javascript, KSS registries in debug mode, or at least re-save them
        • make sure you don't have something in portal_skins/custom or portal_view_customizations that's overriding your filesystem item
        • flush browser cache
    • 57. Why aren't my changes coming alive?
      • changes to python code or ZCML:
        • restart Zope, or use plone.reload
    • 58. Why aren't my changes coming alive?
      • changes to GenericSetup profiles:
        • re-run profile or reinstall product (don't need to restart zope)
      • installing a new product:
        • if not in the Products namespace, did you add a ZCML slug?
    • 59. Debugging KSS
      • Use the FireKiss add-on for Firebug: http://tinyurl.com/firekiss
      • Configure KSS debug log at /@@kss_devel_mode/ui
      • Be aware that KSS will time out if you try to put a pdb set_trace in your server-side KSS action code
    • 60. Common red herrings
    • 61. “Not authorized to access binding.”
      • A deferred permission error from earlier in code execution.
      • See http://tinyurl.com/unauthorizedbinding
    • 62. Quick Installer swallows import errors
      • (Fixed in Plone 3.1.2)
    • 63. AttributeError: getGroups
      • Usually means you moved the site to a new Zope, whose acl_users needs to be converted to be PAS-enabled.
      • You can trigger that conversion by adding a brand new Plone site.
    • 64. “No traversable adapter found.”
      • Usually a symptom of Five failing to load.
      • Start Zope in foreground mode and watch the console for the real traceback.
    • 65.  
    • 66. Credits
      • Cave openings, screenshots – David Glick
      • First computer bug – US Navy / public domain
      • Flickr users:
        • rotten apples – alisonedunn – CC Attribution
        • gearing up for spelunking – jarvist – CC Attribution
        • pause button – Jobot Da Robot – CC Attribution Share Alike
        • “ debug yourself” – joshlewis – CC Attribution NC Share Alike
        • “ no fish” – waldopepper – CC Attribution NC
      • These slides are licensed under the following license: Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

    ×