Re: [Zope-dev] Two glaring omissions
Toby Dickenson <mbel44@dial.pipex.net> wrote:
On Tue, 14 Nov 2000 15:39:59 -0500, Shane Hathaway <shane@digicool.com> wrote:
2. The ability to rename properties after instances of the classes have been created (and have the data in those fields preserved)
This is also more difficult than it sounds. You'd have to either scan through the entire ZODB and modify class instances or associate properties with a magical, unchanging ID. The latter solution is dead wrong, but the first is actually kind of interesting. If there were a separate index for each object type in the ZODB, it would be possible. In fact, when ZODB is running from a relational database, there is indeed a way to do that. Hmmm...
Or if your ZClass has a python base class, then a __setstate__ method could be added to do the same thing incrementally. Like all changes to a Python base class, this requires restarting the server.
Correct in theory, but broken in practice: if you make your ZClass persistent (i.e., you leave checked the "Include standard Zope persistent object base classes?" checkbox on the "Add ZClass form), then Persistent will be the first base class in the list, and *your* '__setstate__' will never be called! Unchecking the box doesn't help, as you then have a ZClass which doesn't (probably) get pickled into the ZODB, so it never needs '__setstate__' atall. Catch-22'ly, Tres. -- =============================================================== Tres Seaver tseaver@digicool.com Digital Creations "Zope Dealers" http://www.zope.org
On Thu, 16 Nov 2000 19:51:24 -0500, Tres Seaver <tseaver@digicool.com> wrote:
Toby Dickenson <mbel44@dial.pipex.net> wrote:
On Tue, 14 Nov 2000 15:39:59 -0500, Shane Hathaway <shane@digicool.com> wrote:
2. The ability to rename properties after instances of the classes have been created (and have the data in those fields preserved)
This is also more difficult than it sounds. You'd have to either scan through the entire ZODB and modify class instances or associate properties with a magical, unchanging ID. The latter solution is dead wrong, but the first is actually kind of interesting. If there were a separate index for each object type in the ZODB, it would be possible. In fact, when ZODB is running from a relational database, there is indeed a way to do that. Hmmm...
Or if your ZClass has a python base class, then a __setstate__ method could be added to do the same thing incrementally. Like all changes to a Python base class, this requires restarting the server.
Correct in theory, but broken in practice: if you make your ZClass persistent (i.e., you leave checked the "Include standard Zope persistent object base classes?" checkbox on the "Add ZClass form), then Persistent will be the first base class in the list, and *your* '__setstate__' will never be called!
Some more theory thats not backed up by any practical experience in this area: Would it be sufficent to create a base class that derives from Persistent and then uncheck the box? or does that checkbox get involved in some other magic? Toby Dickenson tdickenson@geminidataloggers.com
On Mon, 20 Nov 2000, Toby Dickenson wrote:
On Thu, 16 Nov 2000 19:51:24 -0500, Tres Seaver <tseaver@digicool.com> wrote: <snip>
Correct in theory, but broken in practice: if you make your ZClass persistent (i.e., you leave checked the "Include standard Zope persistent object base classes?" checkbox on the "Add ZClass form), then Persistent will be the first base class in the list, and *your* '__setstate__' will never be called!
Some more theory thats not backed up by any practical experience in this area: Would it be sufficent to create a base class that derives from Persistent and then uncheck the box? or does that checkbox get involved in some other magic?
Actually, I was mistaken. I was spelunking through the ZClass code (.../lib/python/ZClasses/*.py) this weekend, working on my filesystem dumper; *all* ZClasses declare ZClasses.ZClass.PersistentClass as the first class in their base class list; this class derives only from ExtensionClass.Base, and not from Persistence.Persistent; I don't any longer know *why* my ZClasses' '__setstate__' would not be called! The 'zope_object' flag passed to 'manage_addZClass' causes OFS.SimpleItem.Item to be *appended* to the base class list (so it should have no effect on the '__setstate__' lookup). Tres. -- =============================================================== Tres Seaver tseaver@digicool.com Digital Creations "Zope Dealers" http://www.zope.org
Toby Dickenson wrote:
On Thu, 16 Nov 2000 19:51:24 -0500, Tres Seaver <tseaver@digicool.com> wrote:
Toby Dickenson <mbel44@dial.pipex.net> wrote:
On Tue, 14 Nov 2000 15:39:59 -0500, Shane Hathaway <shane@digicool.com> wrote:
2. The ability to rename properties after instances of the classes have been created (and have the data in those fields preserved)
This is also more difficult than it sounds. You'd have to either scan through the entire ZODB and modify class instances or associate properties with a magical, unchanging ID. The latter solution is dead wrong, but the first is actually kind of interesting. If there were a separate index for each object type in the ZODB, it would be possible. In fact, when ZODB is running from a relational database, there is indeed a way to do that. Hmmm...
Or if your ZClass has a python base class, then a __setstate__ method could be added to do the same thing incrementally. Like all changes to a Python base class, this requires restarting the server.
Correct in theory, but broken in practice: if you make your ZClass persistent (i.e., you leave checked the "Include standard Zope persistent object base classes?" checkbox on the "Add ZClass form), then Persistent will be the first base class in the list, and *your* '__setstate__' will never be called!
Some more theory thats not backed up by any practical experience in this area: Would it be sufficent to create a base class that derives from Persistent and then uncheck the box? or does that checkbox get involved in some other magic?
Here's an idea... what we might look at is adding another method call to ZODB.Connection.setstate(). In fact, we could cause it to call the new method on behalf of every base class. It would work well, I think, but I still don't know how much merit this idea has. Shane
I tried following one of the Zope Book examples to no avail.
From the scripting chapter:
"Since Python Methods are bound the Zope objects, you can get access to Zope objects via the context parameter. For example, this methods returns the number of objects contained by a given Zope object: Method id: numberOfObjects Parameters: return len(context.objectIds())" I just get a Name Error on context and if I add context as a parameter I just get told that the parameter was omitted from the request. This works, however: Method id: numberOfObjects Parameters: self return len(self.objectIds()) Am I missing something? Is this because Amos and Michel seem to be using 2.2.3 and I'm using 2.2.2? adTHANKSvance Chris
Chris Gray wrote:
I tried following one of the Zope Book examples to no avail.
From the scripting chapter:
"Since Python Methods are bound the Zope objects, you can get access to Zope objects via the context parameter. For example, this methods returns the number of objects contained by a given Zope object:
Method id: numberOfObjects Parameters:
return len(context.objectIds())"
I just get a Name Error on context and if I add context as a parameter I just get told that the parameter was omitted from the request. This works, however:
Method id: numberOfObjects Parameters: self
return len(self.objectIds())
Am I missing something? Is this because Amos and Michel seem to be using 2.2.3 and I'm using 2.2.2?
They are using an unreleased version of the Python Methods product. AFAIK the only thing holding up the release of the new Python Methods is the renaming. Shane
On Mon, 20 Nov 2000, Shane Hathaway wrote:
They are using an unreleased version of the Python Methods product. AFAIK the only thing holding up the release of the new Python Methods is the renaming.
(I believe the version in question is available from the public CVS repository, as the Products/DC/PythonMethod module.) (Ken) klm@digicool.com
participants (5)
-
Chris Gray -
Ken Manheimer -
Shane Hathaway -
Toby Dickenson -
Tres Seaver