schema upgrades with zope.formlib + FIX

Johannes Raggam <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <1297772462.5889.20.camel@nano>
dear zopistas,

while trying to add a new schema field to an already registered plone
portlet, i got following traceback:

2011-02-14 23:11:55 ERROR Zope.SiteErrorLog 1297721515.110.63984381121
http://localhost:8880/info/uber-uns/geschichte/++contextportlets
++plone.rightcolumn/show-galleries-portlet/edit
Traceback (innermost last):
  Module ZPublisher.Publish, line 127, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 47, in call_object
  Module plone.app.portlets.browser.formhelper, line 123, in __call__
  Module zope.formlib.form, line 782, in __call__
  Module five.formlib.formbase, line 50, in update
  Module zope.formlib.form, line 745, in update
  Module zope.formlib.form, line 820, in setUpWidgets
  Module zope.formlib.form, line 408, in setUpEditWidgets
  Module zope.schema._bootstrapfields, line 173, in get
AttributeError: image_size

while - IMO - zope.schema throws that error justifiably, i think
zope.formlib should handle it more gracefully in setUpEditWidgets. i
think, this error comes with every schema upgrade for zope.formlib based
edit-forms. so, what do you think of following patch?

"""
>From bcf7e2b7cb94b145cd502ad57e1363f2e6b4a879 Mon Sep 17 00:00:00 2001
From: Johannes Raggam <[email protected]>
Date: Tue, 15 Feb 2011 12:38:50 +0100
Subject: [PATCH] after schema upgrades (e.g. for plone.app.portlets),
the edit screen cannot be rendered because there is no v
alue for the new field attribute. in this case, use the default value.

---
 zope/formlib/form.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/zope/formlib/form.py b/zope/formlib/form.py
index 5df88cf..0d3ade3 100755
--- a/zope/formlib/form.py
+++ b/zope/formlib/form.py
@@ -405,7 +405,11 @@ def setUpEditWidgets(form_fields, form_prefix,
context, request,
 
         if ignore_request or readonly or not widget.hasInput():
             # Get the value to render
-            value = field.get(adapter)
+            try:
+                value = field.get(adapter)
+            except AttributeError:
+                # value not available after schema upgrade
+                value = field.default
             widget.setRenderedValue(value)
 
         widgets.append((not readonly, widget))
-- 
1.7.1

"""

i'm not sure if this would cause any unwanted side effects... actually i
think it won't.



regards,
johannes raggam


-- 
johannes raggam / thet
python plone zope development
http://johannes.raggam.co.at/
mailto:[email protected]
http://bluedynamics.com/

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.