Hooray, it was just a typo. The method should be called 'validator' rather than 'validate'.
I was going by the documentation that any constructor arg that's a callable type can be replaced by a method. http://docs.pylonsproject.org/projects/colander/en/latest/basics.html#subclassing-schemanode On Wed, Dec 11, 2013 at 11:16 AM, Vincent Catalano <[email protected]> wrote: > No. The validate method should not return anything. I noticed that your > validate method is an instance method. I'm not sure that should be the case. > Try changing the method to a static method or remove it from your class. > > Also, I assume you're calling 'deserialize' on your cstruct? > > > On Wed, Dec 11, 2013 at 12:10 PM, Mike Orr <[email protected]> wrote: >> >> The values are changing from strings to date objects, and if I put a >> self.raise_invalid() in the method it raises it. Am I supposed to >> 'return True' from the method or something? >> >> On Wed, Dec 11, 2013 at 10:33 AM, Vincent Catalano >> <[email protected]> wrote: >> > Ah, it appears you are correct. >> > >> > Are you sure your validate method is being called? After reviewing some >> > of >> > my code where I change data using the colander validate method, it seems >> > that your code should work. >> > >> > -Vincent >> > >> > >> > >> > >> > On Tue, Dec 10, 2013 at 11:23 PM, Mike Orr <[email protected]> wrote: >> >> >> >> The validator is modifying the cstruct dict. >> >> >> >> My understanding about after_bind is that it's to set configuration >> >> parameters for the validators; i.e., control values to check against, >> >> not the deserialized data directly. >> >> >> >> On Tue, Dec 10, 2013 at 10:00 PM, Vincent Catalano >> >> <[email protected]> wrote: >> >> > How are you trying to modify the data? You could use the 'after_bind' >> >> > callback function. >> >> > >> >> > On Dec 10, 2013 6:31 PM, "Mike Orr" <[email protected]> wrote: >> >> >> >> >> >> Can a Colander validator modify data? I assumed it could because >> >> >> FormEncode does, but my tests show the cstruct isn't changing. >> >> >> >> >> >> class SearchSchema(MappingSchema): >> >> >> .... >> >> >> start = SchemaNode(Date(), missing=None) >> >> >> end = SchemaNode(Date(), missing=None) >> >> >> >> >> >> def validate(self, node, cstruct): >> >> >> """Reverse start and end dates if out of order.""" >> >> >> start = cstruct["start"] >> >> >> end = cstruct["end"] >> >> >> if start and end and start > end: >> >> >> cstruct["start"], cstruct["end"] = end, start >> >> >> >> >> >> Otherwise, the only way to modify data seems to be in the type >> >> >> objects, but that won't work for this because its scope is a single >> >> >> field. >> >> >> >> >> >> -- >> >> >> Mike Orr <[email protected]> >> >> >> >> >> >> -- >> >> >> You received this message because you are subscribed to the Google >> >> >> Groups >> >> >> "pylons-discuss" group. >> >> >> To unsubscribe from this group and stop receiving emails from it, >> >> >> send >> >> >> an >> >> >> email to [email protected]. >> >> >> To post to this group, send email to >> >> >> [email protected]. >> >> >> Visit this group at http://groups.google.com/group/pylons-discuss. >> >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > >> >> > -- >> >> > You received this message because you are subscribed to the Google >> >> > Groups >> >> > "pylons-discuss" group. >> >> > To unsubscribe from this group and stop receiving emails from it, >> >> > send >> >> > an >> >> > email to [email protected]. >> >> > To post to this group, send email to [email protected]. >> >> > Visit this group at http://groups.google.com/group/pylons-discuss. >> >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> >> >> >> -- >> >> Mike Orr <[email protected]> >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> >> Groups >> >> "pylons-discuss" group. >> >> To unsubscribe from this group and stop receiving emails from it, send >> >> an >> >> email to [email protected]. >> >> To post to this group, send email to [email protected]. >> >> Visit this group at http://groups.google.com/group/pylons-discuss. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> > >> > >> > >> > >> > -- >> > Vincent Catalano >> > Software Engineer and Web Ninja, >> > (520).603.8944 >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "pylons-discuss" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> > an >> > email to [email protected]. >> > To post to this group, send email to [email protected]. >> > Visit this group at http://groups.google.com/group/pylons-discuss. >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> -- >> Mike Orr <[email protected]> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "pylons-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/pylons-discuss. >> For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > Vincent Catalano > Software Engineer and Web Ninja, > (520).603.8944 > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/pylons-discuss. > For more options, visit https://groups.google.com/groups/opt_out. -- Mike Orr <[email protected]> -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/groups/opt_out.
