Question about expression evaluation

Scott Gould zinckiwi at gmail.com
Mon Nov 8 12:45:29 EST 2010


Thanks for the ideas, everyone. It's probably obvious that this is in
a Django context, and while I do have WSGI configured to multi-thread
its processes, there is nothing explicitly shared -- via threading, a
multi-user situation, or otherwise -- about this data. It is entirely
local to the request so I can't figure out how the "contact" object
could change in a single line of code.

But obviously there must be something going on like what you all
suggest. I just can't figure out how. This is the entirety of the
contact-producing code within Account:

	@property
	def contact(self):
		if not hasattr(self, '_contact'):
			self._contact = get_contact_for_id(self.profile.id) if self.profile
and self.profile.id else None
		return self._contact

As you can see, it's essentially read-only so once a self._contact
always a self._contact. (Unless I'm misunderstanding something
fundamental, which as an admitted amateur I could well be!)

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!




More information about the Python-list mailing list