The best solution is to make (if possible) the identityProvider
a Singleton and make it thread safe !

Anyway TG could always reuse the same provider insite a thread!

Finally this is not really a bug but an unexpected and sometime
costly feature!

Regards.

On 6 avr, 19:45, aspineux <[EMAIL PROTECTED]> wrote:
> I was trying to understand why my custom identity provider was
> initialyzed so many times!
> I raised an exception in __init__ at 3th object creation an get this:
>
> job.py is ran in a scheduled task, and create users from external
> events.
>
> Traceback (most recent call last):
>   File "/s0/asx/src/emailgency/trunk/emailgency/jobs.py", line 273, in
> __call__
>     user=model.User(user_name=user_name, email_addr=user_name,
> display_name=user_name, password='ldap')
>   File "/kolab/lib/python/site-packages/SQLAlchemy-0.4.0-py2.5.egg/
> sqlalchemy/orm/attributes.py", line 1021, in init
>     extra_init(class_, oldinit, instance, args, kwargs)
>   File "/kolab/lib/python/site-packages/SQLAlchemy-0.4.0-py2.5.egg/
> sqlalchemy/orm/mapper.py", line 669, in extra_init
>     self.extension.init_instance(self, class_, oldinit, instance,
> args, kwargs)
>   File "/kolab/lib/python/site-packages/SQLAlchemy-0.4.0-py2.5.egg/
> sqlalchemy/orm/util.py", line 138, in _do
>     ret = getattr(elem, funcname)(*args, **kwargs)
>   File "/kolab/lib/python/site-packages/SQLAlchemy-0.4.0-py2.5.egg/
> sqlalchemy/orm/scoping.py", line 127, in init_instance
>     setattr(instance, key, value)
>   File "/s0/asx/src/emailgency/trunk/emailgency/model.py", line 280,
> in _set_password
>     self._password = identity.encrypt_password(password)
>   File "build\bdist.win32\egg\turbogears\identity\__init__.py", line
> 156, in encrypt_password
>   File "build\bdist.win32\egg\turbogears\identity\__init__.py", line
> 98, in __getattr__
>
> The error is here at line 98
>
> class ProviderWrapper(object):
>
>     def __getattr__(self, name):
>         try:
>             provider= cherrypy.request.identityProvider
>         except AttributeError:
>             try:
>                 provider = create_default_provider() <-- LINE 92
>             except:
>                 provider= None
>
>         if provider is None:
>             if not request_available():
>                 raise RequestRequiredException()  <-- LINE 98
>             raise IdentityManagementNotEnabledException()
>
>         return getattr(provider, name)
>
> But the problem is at line 92 !
> Tg should always reuse the same provider !
> And not create a new one every time I create a new user !
>
> Any comment ?
>
> I solved this by removing the password property from my User class in
> model.py
>
> class User(object):
> ...
>     def _set_password(self, password):
>         """
>         encrypts password on the fly using the encryption
>         algo defined in the configuration
>         """
>         self._password = identity.encrypt_password(password)
>
>     def _get_password(self):
>         """
>         returns password
>         """
>         return self._password
>
>     # password = property(_get_password, _set_password)
>
> Another problem is :
>
> TG create already 2 provider at startup!
>
> in identity/visitor.py
>
> def start_extension():
>     # Bail out if the application hasn't enabled this extension
>     if not turbogears.config.get("identity.on", False):
>         return
>
>     # Identity requires that Visit tracking be enabled
>     if not turbogears.config.get("visit.on", False):
>         raise IdentityConfigurationException(
>                 "Visit tracking must be enabled (visit.on)")
>
>     log.info("Identity starting")
>     # Temporary until tg-admin can call create_extension_model
> *    create_extension_model()
>     # Register the plugin for the Visit Tracking framework
> *    visit.enable_visit_plugin(IdentityVisitPlugin())
>
> both * lines creat an identity provider !
> I thing the first one shoul be reused by the second one.
>
> Regards.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to