Identity TG_User and tg-admin shell still not working together in 0.9a2?

29 views
Skip to first unread message

Jason Chu

unread,
Mar 29, 2006, 7:11:36 PM3/29/06
to turbo...@googlegroups.com
For some reason I thought this was addressed before release.

I'm pretty sure I'm running everything up to date.

With a newly quickstarted project, visit and identity enabled, and
having run the app once (to actually create the tg_* tables, I run
tg-admin shell and try to create a TG_User. I'm getting this error:

>>> TG_Group(groupId='a', displayName='a')
<TG_Group 1 groupId=u'a' displayName=u'a'
created='datetime.datetime...)'>
>>> TG_User(userId='a', password='a', displayName='a',
>>> group=TG_Group.get(1), emailAddress='a')
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/home/jchu/coding/sqlobject/trunk/sqlobject/declarative.py",
line 93, in _wrapper return_value = fn(self, *args, **kwargs)
File "/home/jchu/coding/sqlobject/trunk/sqlobject/main.py", line
1214, in __init__ self._create(id, **kw)
File
"/home/jchu/coding/sqlobject/trunk/sqlobject/inheritance/__init__.py",
line 302, in _create super(InheritableSQLObject, self)._create(id,
**kw) File "/home/jchu/coding/sqlobject/trunk/sqlobject/main.py", line
1240, in _create self.set(**kw) File
"/home/jchu/coding/sqlobject/trunk/sqlobject/main.py", line 1106, in
set setattr(self, name, value) File
"/home/jchu/coding/turbogears/turbogears/identity/soprovider.py", line
298, in _set_password hash =
identity.current_provider.encrypt_password(cleartext_password) File
"/home/jchu/coding/turbogears/turbogears/identity/__init__.py", line
79, in __getattr__ raise RequestRequiredException()
RequestRequiredException: An attempt was made to use a facility of the
TurboGears Identity Management framework that relies on an HTTP request
outside of a request.

Just skimming the code, it looks like the provider is created by
calling create_default_provider. Can't we just call that when initing the shell?

Jason

signature.asc

Jeff Watkins

unread,
Mar 29, 2006, 9:30:28 PM3/29/06
to turbo...@googlegroups.com
I added the code that checks for the presence of a request and
throws, er, raises a more descriptive exception than
IdentityManagementNotEnabledException, because Identity might
actually BE enabled.

Basically, there's no identity provider (or you wouldn't be seeing an
exception at all).

--
Jeff Watkins
http://newburyportion.com/

Democracy n: A country where the newspapers are pro-American.


Jason Chu

unread,
Mar 30, 2006, 12:40:25 PM3/30/06
to turbo...@googlegroups.com
On Wed, 29 Mar 2006 21:30:28 -0500
Jeff Watkins <je...@newburyportion.com> wrote:

>
> I added the code that checks for the presence of a request and
> throws, er, raises a more descriptive exception than
> IdentityManagementNotEnabledException, because Identity might
> actually BE enabled.
>
> Basically, there's no identity provider (or you wouldn't be seeing
> an exception at all).

Yeah, but this is just with a tg-admin shell. There is no identity
provider and also no request.

It looks like line 299 was added to soprovider.py so that users could
be created from within the tg-admin shell. If I were to guess, the new
exception is no longer being caught for this case.

On my initial analysis of this thing, I found the only place that
providers were actually being created was
identity.create_default_provider(). It reads the identity.provider
config option, which will have been set by the time tg-admin shell
gives the user control (or any other time you're accessing turbogears).

Why wouldn't we try creating a default provider when there is no
request? That way the ProviderWrapper would raise an exception only if
there was no request and the tg config options weren't set. At that
point, I think it's pretty safe to say we don't know what to do. I'm
not quite sure why we need a request to be created to have a provider.

If we did this, I believe the code within _set_password for TG_User (the
stuff around line 299), wouldn't even be needed, because we'd get the
proper provider no matter what (instead of just assuming they wanted to
SqlObjectIdentityProvider).

If I'm not making myself clear, I have a diff that should explain
me better:

Index: turbogears/identity/__init__.py
===================================================================
--- turbogears/identity/__init__.py (revision 1040)
+++ turbogears/identity/__init__.py (working copy)
@@ -72,7 +72,10 @@
try:
provider= cherrypy.request.identityProvider
except AttributeError:
- provider= None
+ try:
+ provider = create_default_provider()
+ except:
+ provider= None

if provider is None:
if not request_available():

Jason

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "TurboGears" group. To post to this group, send email to
> turbo...@googlegroups.com To unsubscribe from this group, send
> email to turbogears-...@googlegroups.com For more options,
> visit this group at http://groups.google.com/group/turbogears
> -~----------~----~----~----~------~----~------~--~---
>

signature.asc

gasolin

unread,
Mar 30, 2006, 10:39:11 PM3/30/06
to TurboGears
Jason :

The patch works, Thanks!

--
Fred

Reply all
Reply to author
Forward
0 new messages