[Checkins] SVN: zope.schema/trunk/ fix broken Object field validation. Previous version was using a volatile property on object field values which ends in a ForbiddenAttribute error on security proxied objects.
Roger Ineichen
roger at projekt01.ch
Fri Sep 23 09:00:52 EST 2011
Log message for revision 122904:
fix broken Object field validation. Previous version was using a volatile property on object field values which ends in a ForbiddenAttribute error on security proxied objects.
Changed:
U zope.schema/trunk/CHANGES.txt
U zope.schema/trunk/src/zope/schema/_field.py
-=-
Modified: zope.schema/trunk/CHANGES.txt
===================================================================
--- zope.schema/trunk/CHANGES.txt 2011-09-23 08:41:02 UTC (rev 122903)
+++ zope.schema/trunk/CHANGES.txt 2011-09-23 14:00:51 UTC (rev 122904)
@@ -5,7 +5,9 @@
3.8.1 (unreleased)
------------------
-- ...
+- fix broken Object field validation. Previous version was using a volatile
+ property on object field values which ends in a ForbiddenAttribute error
+ on security proxied objects.
3.8.0 (2011-03-18)
------------------
Modified: zope.schema/trunk/src/zope/schema/_field.py
===================================================================
--- zope.schema/trunk/src/zope/schema/_field.py 2011-09-23 08:41:02 UTC (rev 122903)
+++ zope.schema/trunk/src/zope/schema/_field.py 2011-09-23 14:00:51 UTC (rev 122904)
@@ -18,6 +18,7 @@
import re
import decimal
+import threading
from datetime import datetime, date, timedelta, time
from zope.event import notify
@@ -452,6 +453,8 @@
super(FrozenSet, self).__init__(unique=True, **kw)
+VALIDATED_VALUES = threading.local()
+
def _validate_fields(schema, value, errors=None):
if errors is None:
errors = []
@@ -462,13 +465,12 @@
if schema is Interface:
return errors
# if `value` is part of a cyclic graph, we need to break the cycle to avoid
- # infinite recursion.
- #
- # (use volatile attribute to avoid persistency/conflicts)
- if hasattr(value, '_v_schema_being_validated'):
+ # infinite recursion. Collect validated objects in a thread local dict by
+ # it's python represenation. A previous version was setting a volatile
+ # attribute which didn't work with security proxy
+ if id(value) in VALIDATED_VALUES.__dict__:
return errors
- # Mark the value as being validated.
- value._v_schema_being_validated = True
+ VALIDATED_VALUES.__dict__[id(value)] = True
# (If we have gotten here, we know that `value` provides an interface
# other than zope.interface.Interface;
# iow, we can rely on the fact that it is an instance
@@ -487,7 +489,7 @@
# property for the given name is not implemented
errors.append(SchemaNotFullyImplemented(error))
finally:
- delattr(value, '_v_schema_being_validated')
+ del VALIDATED_VALUES.__dict__[id(value)]
return errors
More information about the checkins
mailing list