[PEAK] Strange behaviour

Phillip J. Eby pje at telecommunity.com
Wed Jul 20 12:48:44 EDT 2005


At 09:00 PM 7/19/2005 +0000, Tiago Cogumbreiro wrote:
>Hello list,
>
>While doing a very small example the strangest thing happened. I am
>registring my models in the [Component Factories] entry of the INI
>file, just as the bulletins example. The problem is, when I try to use
>the DM _the first_ an error about not being able to import the module
>appears. I am using this in a test case and as you can see the second
>time it's run the problem silently goes away.
>
>Can someone help me spot what am I doing wrong?

Your helpdesk/__init__.py imports 'storage' from peak.api, and importString 
picks this up as being 'helpdesk.storage'.  It then tries to retrieve 
'ClientDM' from peak.storage.api as a result.  When this fails, it falls 
back to attempting to import 'helpdesk.storage.ClientDM' as a module.  This 
fails, but it causes the correct 'helpdesk.storage' module to be loaded as 
a side effect, such that subsequent checks work.

So, in helpdesk/__init__.py you shouldn't use 'from peak.api import *'; 
it's generally not a great idea to put much in __init__.py files anyway.

I could probably also change importString() to try importing *before* doing 
getattr(), and maybe display better error information, but I'm not sure 
when I'll have time to do that and figure out some tests for it.




More information about the PEAK mailing list