Question about expression evaluation

Scott Gould zinckiwi at
Mon Nov 8 18:45:29 CET 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:

	def contact(self):
		if not hasattr(self, '_contact'):
			self._contact = get_contact_for_id( if self.profile
and 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> wrote:
> Hi folks,
> This is a head-scratcher to me. I occasionally get this error:
> ---
>   File "/var/www/myproj/account/", line 54, in account
>     if request.account.is_instructor and and
> 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
> "" is None, how is it even getting as far as
> ""?
> Thanks!

More information about the Python-list mailing list