Ticket #865 (defect)
Opened 1 month ago
Last modified 2 weeks ago
_ThreadLocalProxy's child may not have a size
Status: closed (fixed)
| Reported by: | johansen@sun.com | Assigned to: | fumanchu |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | CherryPy code | Keywords: | |
| Cc: | swalker@opensolaris.org |
In some code that I was writing for OpenSolaris's packaging tool, I passed a CherryPy.response object into a routine and then wrote this:
if rspobj: rspobj.headers['Content-Length'] = str(self.size())
However, this didn't have the desired effect. When this code was run, it produced the following error in cherrypy/init.py:
File "<...>/cherrypy/__init__.py", line 339, in __len__ TypeError: len() of unsized object
This corresponds to _ThreadLocalProxy's __len__() method. This method looks up self.__attrname__ on serving, assigns that to child, and then returns len(child).
In this case, there doesn't appear to be any way to determine the size of child.
I'd also argue that this isn't the desired behavior for truth value testing. Since I just want to know if the object exists, the presence of a __nonzero__ method would prevent an if from falling back to __len__ in situations like these.
For the meantime, I was able to work around this by testing if rspobj is not None.
However, we ought to make sure that it's possible to call len() on child before actually doing so. It also wouldn't hurt to add a __nonzero__ method to this object.
Change History
11/08/08 16:25:26: Modified by fumanchu
- status changed from new to closed.
- resolution set to fixed.


Fixed in [2078].