Persistence and __getattr__
It appears to me that if you have a class object that you want to be Persistence, all the object attributes have to be in object.__dict__ or Persistence.__getattr__ has no way of retrieving them. This at first seems pretty obvious, but what about instances where your object attributes change outside of zope? I can't determine any way to trigger an 'attribute refresh' on a __getattr__ failure if the attribute does not exist in the object.__dict__. Is this correct? Is it that 'volatile' attributes cannot be Persistent? I see that when I try to override Persistence.__getattr__ in order to add the capability to create or change attributes while still seemingly duplicating the the method instructions, I encounter an infinite loop. :^) Yes, I read the docs, but I'm trying to figure out if there is perhaps a way around this puzzle. Thanks Kent
Kent Polk wrote:
It appears to me that if you have a class object that you want to be Persistence, all the object attributes have to be in object.__dict__ or Persistence.__getattr__ has no way of retrieving them.
This is right, unless you are willing to go down to the C level.
This at first seems pretty obvious, but what about instances where your object attributes change outside of zope?
Why are these objects persistent? If they are persistent, then their data is stored in Zope and doesn't change outside of Zope.
I can't determine any way to trigger an 'attribute refresh' on a __getattr__ failure if the attribute does not exist in the object.__dict__.
Right.
Is this correct?
Yes. It sounds like you don't want a persistent object at all. You want an object that get's it's data from somewhere else (somewhere other than the object database). You can have a sub-object of a persistent object that is not persistent and gets *it's* data from somewhere else. This is essentially what happens with database connections and SQL methods.
Is it that 'volatile' attributes cannot be Persistent?
There's no point in making them persistent, since they won't be stored in the database. :)
I see that when I try to override Persistence.__getattr__ in order to add the capability to create or change attributes while still seemingly duplicating the the method instructions, I encounter an infinite loop. :^) Yes, I read the docs, but I'm trying to figure out if there is perhaps a way around this puzzle.
Don't override __getattr__ or __setattr__ for subclasses of Persistent. (It *can* be done, but it requires such *deep* zen that it makes *my* head hurt. There is actually a class used by ZClasses that does this. :) Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
Jim Fulton wrote:
Kent Polk wrote:
It appears to me that if you have a class object that you want to be Persistence, all the object attributes have to be in object.__dict__ or Persistence.__getattr__ has no way of retrieving them.
This is right, unless you are willing to go down to the C level.
Why are these objects persistent? If they are persistent, then their data is stored in Zope and doesn't change outside of Zope.
Yes. It sounds like you don't want a persistent object at all. You want an object that get's it's data from somewhere else (somewhere other than the object database).
I was attempting to provide a convenient way to load and refresh attributes into the Zope database and still make use of Persistent's caching abilities, etc.
You can have a sub-object of a persistent object that is not persistent and gets *it's* data from somewhere else. This is essentially what happens with database connections and SQL methods.
Yeah. Considered that, but I doesn't really gain me anything in this case, as all the objects would have volatile attributes. Thanks Kent
I need to be able to install files required by a product (i.e. javascript files) without user intervention. I actually want them stored as files in Zope to take advantage of browser caching, as some of the script files are quite large and downloading them with each page via DTML is slowing things down. What is the best way to do this ? Thanks in advance, Robert Leftwich
participants (4)
-
Jim Fulton -
Kent Polk -
kent@tiamat.goathill.org -
Robert Leftwich