zope.schema does not handle well nested object fields

Bug #969350 reported by Alex Garel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zope.schema
Won't Fix
Undecided
Unassigned

Bug Description

using trunk version of zope.schema, if I use an Object field whose schema has a Set (or any Collection) of Choice, it fails validating.

This is due to a bad (inexisting) handling of bind in Object field.

svn commit 112445 [1] solve the bug for the case a a Choice inside an Object, but not in the case of a Choice inside a Set inside an Object.

[1] http://svn.zope.org/zope.schema/trunk/src/zope/schema/_field.py?rev=112445&r1=111614&r2=112445

Revision history for this message
Alex Garel (alex-garel) wrote :

I propose a solution which handles binding not only validation.

There is a difference with previous code : it does not bind inner Choice to Object value but to Object context.

I prefer this solution since binding to value maybe problematic in a lot a cases, eg. when vocabularies depends on object situation in the object tree whereas most of the time, at creation, Object value is not yet tied to any context.

Here is a patch.

Revision history for this message
Alex Garel (alex-garel) wrote :

I precise last point for eventual discussion:

The main point is that my fix propose to bind Object field (as its done for Collections, or Vocabularies) but it introduce a difference with previous behaviour (itself shiped with 3.6.4)

Previously, a Choice field nested in a Object field gets binded to the new value to be assigned to Object field at validation time.
In the fix that I propose. I bind the Choice to the same context as the ObjectField.

This fix which handles Object.bind feels more general to me than an exception in _validate_fields for Choices. It already solves the problem of binding nested Set fields, and will permit a better handling for third party fields which needs binding.

I also prefer this solution since binding to value maybe problematic in a lot a cases, eg. when vocabularies depends on object situation in the object tree whereas most of the time, at creation, Object value is not yet tied to any context.

Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in zope.schema:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.