[Zope3-Users] object has no attribute '_SampleContainer__data'

Jim Fulton jim at zope.com
Wed Oct 5 10:20:43 EDT 2005


Tom Dossis wrote:
> Jim Fulton wrote:
> 
>> Tom Dossis wrote:
>>
>>> Leticia Larrosa wrote:
>>>
>>>> I get the following error:
>>>> """
>>>> 'Service' object has no attribute '_SampleContainer__data'
>>>> """
>>>
>>> I implementend a simple subclass of SampleContainer, then changed to 
>>> subclass BTreeContainer, but forget to delete existing instances 
>>> created in Zope.  A tell tale sign is you can no longer delete the 
>>> broken instance(s)
>>
>>
>> This sounds like a bug.  Could you report this with a specific example?
>>
>> Jim
> 
> 
> 
> I can remember exactly how I naively did this originally, but I can 
> achieve it with a little sabotage..

I missinterpreted your original message.  I thought you were dealing
with Broken objects, not broken objects. :)  Broken objects are objects
that can't be created, usually becase their class isn't around any more.
The system should be able to recognize these and at least allow their
deletion.


> 
>  >>> class Bogus(BTreeContainer): pass
> ...
>  >>> bogus = Bogus()
>  >>> root['bogus'] = bogus = Bogus()
>  >>> del bogus.__dict__['_SampleContainer__data']
>  >>> del root['f']
> Traceback (most recent call last):
>   :
>   File ".. /zope/interface/adapter.py", line 487, in subscribers
>     subscribers = [subscription(*objects)
>   File ".. /zope/app/container/contained.py", line 177, in 
> dispatchToSublocations
>     for sub in subs.sublocations():
>   File ".. /zope/app/container/contained.py", line 208, in sublocations
>     for key in container:
>   File ".. /zope/app/container/sample.py", line 56, in __iter__
>     return iter(self.__data)
> AttributeError: 'Bogus' object has no attribute '_SampleContainer__data'
> 
> 
> Is this a bug because the container now fails to fulfill it's interface 
> causing object propogation to fail?

Yes.

> Is defensive programming desirable or appropriate?

Possibly.  Probably only in the delete-object case.
Ideally, if there was an error when deleting an object,
the error would be reported and some UI might be provided
to force delete even in the face of errors -- perhaps
only if the user has a stronger permission.

> 
> <snippet1 from distpatchToSublocations>
>     subs = ISublocations(object, None)
>     if subs is not None:
>         for sub in subs.sublocations():
> 
> <snippet2 from ContainerSublocations adapter>
>     def sublocations(self)
>         container = self.container
>         for key in container:
>             yield container[key]

I don't know what your point is here.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-users mailing list