identity condition weirdness

0 views
Skip to first unread message

Christophe de VIENNE

unread,
Nov 12, 2008, 4:59:54 AM11/12/08
to turbogea...@googlegroups.com
Hi,

While reading identity.conditions, I noticed this in
not_anonymous.eval_with_object.
Shouldn't line 108 be :

108 if identity.anonymous:

?

The 1.0 branch contains the following :

103 class not_anonymous(Predicate, IdentityPredicateHelper):
104 """Predicate for checking whether current visitor is anonymous."""
105 error_message = "Anonymous access denied"
106
107 def eval_with_object(self, identity, errors=None):
108 if current.anonymous:
109 self.append_error_message(errors)
110 return False
111 return True

I'm just curious.

Regards,

Christophe

Christoph Zwerschke

unread,
Nov 12, 2008, 6:39:02 AM11/12/08
to turbogea...@googlegroups.com
Christophe de VIENNE schrieb:

> Shouldn't line 108 be :
>
> 108 if identity.anonymous:

No, I think current.anonymous is correct; "current" is the identity
wrapper. Maybe you were confused because it's named "identity" in the
template std vars.

-- Christoph

Christophe de VIENNE

unread,
Nov 12, 2008, 11:24:51 AM11/12/08
to turbogea...@googlegroups.com
2008/11/12 Christoph Zwerschke <ci...@online.de>:

The thing is that in the other predicates, "identity" is used. Note
that in this context "identity" is the parameter of the function, not
the identity module.
So my understanding is that the predicate shouldn't access the global
"current" identity but the one given as a parameter.

Christophe

Christopher Arndt

unread,
Nov 12, 2008, 12:11:19 PM11/12/08
to turbogea...@googlegroups.com
Christophe de VIENNE schrieb:

Yes, this is an inconsistency in the code which I also noticed earlier
but didn't have the time to correct. Can you file a bug ticket, please?

It doesn't matter when you use the standard identity decorator, but it
might lead to subtle bugs when customizing the identity predicates.


Chris

Christophe de VIENNE

unread,
Nov 12, 2008, 12:39:05 PM11/12/08
to turbogea...@googlegroups.com
2008/11/12 Christopher Arndt <chris...@web.de>:

>
> Christophe de VIENNE schrieb:
>> 2008/11/12 Christoph Zwerschke <ci...@online.de>:
>>> Christophe de VIENNE schrieb:
>>>> Shouldn't line 108 be :
>>>>
>>>> 108 if identity.anonymous:
>>> No, I think current.anonymous is correct; "current" is the identity
>>> wrapper. Maybe you were confused because it's named "identity" in the
>>> template std vars.
>>>
>>
>> The thing is that in the other predicates, "identity" is used. Note
>> that in this context "identity" is the parameter of the function, not
>> the identity module.
>> So my understanding is that the predicate shouldn't access the global
>> "current" identity but the one given as a parameter.
>
> Yes, this is an inconsistency in the code which I also noticed earlier
> but didn't have the time to correct. Can you file a bug ticket, please?

Done, with a patch for branch 1.0.
http://trac.turbogears.org/ticket/2029

The 1.1 branch is not concerned.

Regards,

Christophe

Christoph Zwerschke

unread,
Nov 12, 2008, 2:51:39 PM11/12/08
to turbogea...@googlegroups.com
Christophe de VIENNE schrieb:

> The thing is that in the other predicates, "identity" is used. Note
> that in this context "identity" is the parameter of the function, not
> the identity module.
> So my understanding is that the predicate shouldn't access the global
> "current" identity but the one given as a parameter.

Ah, sorry, now I see what you mean. It actually amounts to the same,
since "not_anonymous" is intended to be used by the "require" decorator
which always passes "current" as the "identity" parameter. But you're
right, this should at least be handled consistently in all predicates.

-- Christoph

Reply all
Reply to author
Forward
0 new messages