[Twisted-Python] Woven using wrong model adapter

I have: components.registerAdapter(model.ObjectWrapper, interests.InterestChangeReport, wovenInterfaces.IModel) class Page(page.Page): def wmfactory_report(self, request): if sometimes: return deferredInterestChangeReport() else: return '' If the first page I serve after starting the server gets an InterestChangeReport, then everything works just fine. However, if the first page served gets '', then any future page that gets an InterestChangeReport dies with an exception: "the submodel was not found in [<twisted.web.woven.model.StringModel instance at 0x85167c4: wrapped data: <InterestChangeReport instance...>" So why does woven persist in using the StringModel adapter in this case, and how can I get it to stop? Don't know if this is related or not, but the log shows messages like: "Warning: There was no parent for node [...]; node not mutated." Is that something I should be concerned about? Thanks, - Kevin -- The moon is waning crescent, 16.8% illuminated, 25.6 days old.

On 2003.05.26 21:13, Kevin Turner wrote:
...
So why does woven persist in using the StringModel adapter in this case, and how can I get it to stop?
IIRC, A workaround is to 1) put the conditional in a special wvfactory rather than/in addition to your wmfactory, or 2) call self.invalidateCache() every time the result of the conditional changes (or just on every request, if you don't care)
dunno -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://twistedmatrix.com/users/radix.twistd/

On Mon, 2003-05-26 at 18:37, Christopher Armstrong wrote:
Model.invalidateCache is not what's needed here. It turns out that when that cache gets stale (either through explicit invalidateCache or just a new Request), Model.getData will update the model data in Model.original... but it only swaps out the Model.original attribute, it doesn't replace the Model with a new Model adapter for the new data. Which is how I was getting my FooReport instances ending up inside a StringModel adapter. What I've done now is, in Page.request: del self.submodels["report"] This makes sure that old model adapters never hang around. It also smells bad. Am I violating some unwritten contract here which says "a model factory must always return models with the same interface"? -- The moon is waning crescent, 15.6% illuminated, 25.7 days old.

On Monday, May 26, 2003, at 10:02 PM, Kevin Turner wrote:
Am I violating some unwritten contract here which says "a model factory must always return models with the same interface"?
A model factory must always return an object with the same identity within one request. See DeferredModel for an example of how to change the behaviour of an IModel implementor without changing it's identity. You really shouldn't be doing conditional rendering with a wmfactory anyway; put the conditional in the View, where it belongs. dp

On 2003.05.27 01:56, Donovan Preston wrote:
With such a restriction, it seems there's no reason to *call* the model factory multiple times per request. Shouldn't this be prevented? -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://twistedmatrix.com/users/radix.twistd/

On 2003.05.26 21:13, Kevin Turner wrote:
...
So why does woven persist in using the StringModel adapter in this case, and how can I get it to stop?
IIRC, A workaround is to 1) put the conditional in a special wvfactory rather than/in addition to your wmfactory, or 2) call self.invalidateCache() every time the result of the conditional changes (or just on every request, if you don't care)
dunno -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://twistedmatrix.com/users/radix.twistd/

On Mon, 2003-05-26 at 18:37, Christopher Armstrong wrote:
Model.invalidateCache is not what's needed here. It turns out that when that cache gets stale (either through explicit invalidateCache or just a new Request), Model.getData will update the model data in Model.original... but it only swaps out the Model.original attribute, it doesn't replace the Model with a new Model adapter for the new data. Which is how I was getting my FooReport instances ending up inside a StringModel adapter. What I've done now is, in Page.request: del self.submodels["report"] This makes sure that old model adapters never hang around. It also smells bad. Am I violating some unwritten contract here which says "a model factory must always return models with the same interface"? -- The moon is waning crescent, 15.6% illuminated, 25.7 days old.

On Monday, May 26, 2003, at 10:02 PM, Kevin Turner wrote:
Am I violating some unwritten contract here which says "a model factory must always return models with the same interface"?
A model factory must always return an object with the same identity within one request. See DeferredModel for an example of how to change the behaviour of an IModel implementor without changing it's identity. You really shouldn't be doing conditional rendering with a wmfactory anyway; put the conditional in the View, where it belongs. dp

On 2003.05.27 01:56, Donovan Preston wrote:
With such a restriction, it seems there's no reason to *call* the model factory multiple times per request. Shouldn't this be prevented? -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://twistedmatrix.com/users/radix.twistd/
participants (3)
-
Christopher Armstrong
-
Donovan Preston
-
Kevin Turner