Question about expression evaluation

nn pruebauno at latinmail.com
Mon Nov 8 11:38:21 EST 2010


On Nov 8, 11:17 am, Scott Gould <zinck... at gmail.com> wrote:
> Hi folks,
>
> This is a head-scratcher to me. I occasionally get this error:
>
> ---
>   File "/var/www/myproj/account/views.py", line 54, in account
>     if request.account.is_instructor and request.account.contact and
> request.account.contact.relationship.institution_party_number:
>
> AttributeError: 'NoneType' object has no attribute 'relationship'
> ---
>
> I'm leaving out all the supporting code deliberately. My question is
> simple: if python short-circuits evaluation and
> "request.account.contact" is None, how is it even getting as far as
> "request.account.contact.relationship.institution_party_number"?
>
> Thanks!

Hard to tell without details. Maybe request.account.contact is an
impure property with side effects?




More information about the Python-list mailing list