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

2005-10-05 Thread Tom Dossis

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..


 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?


Is defensive programming desirable or appropriate?


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]


-Tom
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-10-05 Thread Jim Fulton

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:[EMAIL PROTECTED]   Python Powered!
CTO  (540) 361-1714http://www.python.org
Zope Corporation http://www.zope.com   http://www.zope.org
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-10-04 Thread Jim Fulton

Tom Dossis wrote:

Leticia Larrosa wrote:

When a try to see the view of list of Service of one of the 
ServiceList

I get the following error:


'Service' object has no attribute '_SampleContainer__data'


I'm newcomer in zope 3 and any idea will be appreciated.
Thanks in advance.

Leticia Larrosa



In addition to the previous reply; I experienced the above problem when..

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

--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
CTO  (540) 361-1714http://www.python.org
Zope Corporation http://www.zope.com   http://www.zope.org
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-10-04 Thread Leticia Larrosa
Hi:

Here are the steps for reproduce the error:

0- Create a package call pbugs and inside them:

1- Create a module with this content:

from zope.interface import Interface
from zope.schema import TextLine
from zope.interface import implements
from zope.app.container.btree import BTreeContainer
from persistent import Persistent
from zope.app.container.interfaces import IContainer
from zope.app.container.constraints import ItemTypePrecondition

class IMessage(Interface):
A message object.

title = TextLine(
title=uTitle/Subject,
description=uTitle and/or subject of the message.,
default=u,
required=True)

class IMessageContainer(IContainer):

def __setitem__(name, object):
Add a IMessage object.

__setitem__.precondition = ItemTypePrecondition(IMessage)

class Message(Persistent):

implements(IMessage)

title = u''


2- create a configure.zcml

configure
xmlns=http://namespaces.zope.org/zope;

  interface 
  interface=pbugs.message.IMessage 
  type=zope.app.content.interfaces.IContentType
  / 

  content class=pbugs.message.Message
implements
interface=zope.app.annotation.interfaces.IAttributeAnnotatable
/

require
permission=zope.ManageContent
interface=pbugs.message.IMessageContainer/

require
permission=zope.ManageContent
interface=pbugs.message.IMessage
/
require
permission=zope.ManageContent
set_schema=pbugs.message.IMessage
/
  /content

  include package=.browser /

/configure


3- and create a browser package and a configure.zcml:

configure
xmlns=http://namespaces.zope.org/browser;

  addform
  label=Add Message
  name=AddMessage.html
  schema=pbugs.message.IMessage
  content_factory=pbugs.message.Message
  fields=title
  permission=zope.ManageContent
  /

  addMenuItem
  class=pbugs.message.Message
  title=Message
  description=A Message
  permission=zope.ManageContent
  view=AddMessage.html 
  /

  editform
  schema=pbugs.message.IMessage
  for=pbugs.message.IMessage
  label=Change Message
  fields=title
  name=edit.html
  permission=zope.ManageContent
  menu=zmi_views title=Edit 
  /

  containerViews
  for=pbugs.message.IMessage
  index=zope.View
  contents=zope.View
  add=zope.ManageContent
  /

/configure

4- start zope and add a content object of type Message in the ZMI

5- Change in message.py:
This:

class Message(Persistent):

implements(IMessage)

title = u''

For this:

class Message(BTreeContainer):

implements(IMessage, IMessageContainer)

title = u''


6- Restart zope, and an error occurs when try to delete the old content
object Message, or when I try to see the content. The error is like I send
in a previous message.

Sorry if I can't minimize the steps for reproduce the error.

In the Zope 3 Developer's Handbook, Richter says:

Note: If you make data-structural changes in your package, it might become
necessary to delete old instances of the objects/components. Sometimes even
this is not enough, so that you have to either delete the parent Folder or
best delete the Data.fs (ZODB) file. There are ways to upgrade gracefully to
new versions of objects, but during development the listed methods are
simpler and faster.


If uses the attach files:
1- copy the extracted files into  C:\Zope3-Instance\lib\python\
2- register the package into C:\Zope3-Instance\etc\package-includes
3- reproduce the steps 4, 5 and 6.

Regards
Leticia

-Original Message-
From: Jim Fulton [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 04, 2005 5:05 AM
To: Tom Dossis
Cc: Leticia Larrosa; zope3-users@zope.org
Subject: Re: [Zope3-Users] object has no attribute '_SampleContainer__data'

Tom Dossis wrote:
 Leticia Larrosa wrote:
 
 When a try to see the view of list of Service of one of the 
 ServiceList
 I get the following error:

 
 'Service' object has no attribute '_SampleContainer__data'
 

 I'm newcomer in zope 3 and any idea will be appreciated.
 Thanks in advance.

 Leticia Larrosa
 
 
 In addition to the previous reply; I experienced the above problem when..
 
 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

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





pbugs.rar
Description: Binary data
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-10-03 Thread Leticia Larrosa

I'm sorry, I forgot to say that: ServiceList and Service are
hypothetical kinds of objects.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of leticia
Sent: Monday, October 03, 2005 1:11 PM
To: zope3-users@zope.org
Subject: [Zope3-Users] object has no attribute '_SampleContainer__data'

Hi:

I have an object ServiceList who inherit from BTreeContainer and
implements IContainer that have inside objects of type Service who
inherit from BTreeContainer too and implements IContained and
IContainer.

When a try to see the view of list of Service of one of the ServiceList
I get the following error:


'Service' object has no attribute '_SampleContainer__data'


And the Traceback is:

Traceback (innermost last):
  Module zope.publisher.publish, line 138, in publish
result = publication.callObject(request, object)
  Module zope.app.publication.zopepublication, line 164, in callObject
return mapply(ob, request.getPositionalArguments(), request)
  Module zope.publisher.publish, line 113, in mapply
return debug_call(object, args)
   - __traceback_info__: BoundPageTemplateFile of
zope.app.publisher.browser.viewmeta.Contents object at 0x03A34530
  Module zope.publisher.publish, line 119, in debug_call
return object(*args)
  Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__
return self.im_func(im_self, *args, **kw)
  Module zope.app.pagetemplate.viewpagetemplatefile, line 51, in __call__
sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  Module zope.pagetemplate.pagetemplate, line 117, in pt_render
strictinsert=0, sourceAnnotations=sourceAnnotations)()
  Module zope.tal.talinterpreter, line 239, in __call__
self.interpret(self.program)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 869, in do_useMacro
self.interpret(macro)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 502, in do_optTag_tal
self.do_optTag(stuff)
  Module zope.tal.talinterpreter, line 487, in do_optTag
return self.no_tag(start, program)
  Module zope.tal.talinterpreter, line 482, in no_tag
self.interpret(program)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 839, in do_defineMacro
self.interpret(macro)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 941, in do_defineSlot
self.interpret(block)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 931, in do_defineSlot
self.interpret(slot)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 839, in do_defineMacro
self.interpret(macro)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 808, in do_loop_tal
self.interpret(block)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 502, in do_optTag_tal
self.do_optTag(stuff)
  Module zope.tal.talinterpreter, line 487, in do_optTag
return self.no_tag(start, program)
  Module zope.tal.talinterpreter, line 482, in no_tag
self.interpret(program)
  Module zope.tal.talinterpreter, line 314, in interpret
handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 617, in do_insertI18nText_tal
text = self.engine.evaluateText(stuff[0])
  Module zope.app.pagetemplate.engine, line 101, in evaluateText
text = self.evaluate(expr)
  Module zope.tales.tales, line 698, in evaluate
return expression(self)
   - C:\Python24\Lib\site-packages\zope\app\container\browser\contents.pt
   - Line 110, Column 16
   - Expression: PathExpr standard:'item/size/sizeForDisplay|nothing'
   - Names:
  {'args': (),
   'context': srcs.configuration.ServiceList object at 0x0221E770,
   'default': object object at 0x0097C500,
   'loop': {},
   'nothing': None,
   'options': {},
   'repeat': {},
   'request': zope.publisher.browser.BrowserRequest instance
URL=http://localhost:8080/services/@@contents.html,
   'template':
zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object at
0x016679B0,
   'usage': zope.pagetemplate.pagetemplate.TemplateUsage object at
0x03A347D0,
   'view': zope.app.publisher.browser.viewmeta.Contents object at
0x03A34530,
   'views': zope.app.pagetemplate.viewpagetemplatefile.ViewMapper
object at 0x0242E090}
  Module zope.tales.expressions, line 204, in __call__
return self._eval(econtext)
  Module zope.tales.expressions, line 198, in _eval
return ob()
  Module zope.app.container.size, line 38, in 

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

2005-10-03 Thread Gary Poster


On Oct 3, 2005, at 9:29 PM, Leticia Larrosa wrote:
AttributeError: 'Service' object has no attribute  
'_SampleContainer__data'


Hi Leticia.  It looks like your container overrides __init__ and,  
rather than deferring to the SampleContainer.__init__, you are trying  
to set the __data value in your own class.  If you are not familiar  
with the magic pseudo-private '__*' behavior in Python, maybe you  
should read up on it.  The immediate fix, though, is to change your  
current SampleContainer __init__.


If now it looks something like this:

class SampleContainer(BTreeContainer):
# ...
def __init__(self):
# ...
self.__data = self._newContainerData()
# ...

then delete than instantiation and instead do this:

class SampleContainer(BTreeContainer):
# ...
def __init__(self):
# ...
super(SampleContainer, self).__init__() # this replaces the  
self.__data line

# ...

That should hopefully clear it up.

If you need to change what is made as the data object, override  
_newContainerData (although that's where the btree mix in does its  
work!).


Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2005-10-03 Thread Leticia Larrosa

Tom and Gary, thanks so much. Tom, was exactly the same problem !!!.
Gary, I will review my knowledge about python following your advice ;)

Regards,
Leticia

-Original Message-
From: Tom Dossis [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 03, 2005 8:09 PM
To: Leticia Larrosa
Cc: zope3-users@zope.org
Subject: Re: [Zope3-Users] object has no attribute '_SampleContainer__data'

Leticia Larrosa wrote:
 When a try to see the view of list of Service of one of the
ServiceList
 I get the following error:
 
 
 'Service' object has no attribute '_SampleContainer__data'
 
 
 I'm newcomer in zope 3 and any idea will be appreciated.
 Thanks in advance.
 
 Leticia Larrosa

In addition to the previous reply; I experienced the above problem when..

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)

-Tom








___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users