I have a Formencode schema that I use when the user saves data from a form as an interim step in their workflow. I'm trying to use a subclass of that schema with modified field attributes for the step when the user if finished their work. Here's a toy example:
>>> import formencode >>> >>> class SaveSchema(formencode.Schema): ... foo = formencode.validators.Set(if_missing=[]) ... >>> class SubmitSchema(SaveSchema): ... def modify_schema(self): ... self.fields['foo'].if_missing = formencode.NoDefault ... The idea of this is that the user can save without having made a selection for foo, but if they try to submit without having done so a formencode.Invalid with be raised. This arrangement appears to work in my app, but I'm seeing some weirdness in my tests that I can reproduce from this toy example: >>> schema = SchemaSave() >>> assert schema.fields['foo'].if_missing == [] >>> >>> schema = SchemaSubmit() >>> schema.modify_schema() >>> assert schema.fields['foo'].if_missing == formencode.NoDefault >>> >>> schema = SchemaSave() >>> assert schema.fields['foo'].if_missing == [] Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError >>> >>> assert schema.fields['foo'].if_missing == formencode.NoDefault >>> It appears that the 2nd instance of SaveSchema() is not, in fact, a new instance. It carries the result of modify_schema(). Am I doing something horribly wrong by trying to modify a schema like this? Doug -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
