Hi Massimo -- The change I made is in the first message of this thread. I just changed one line in the definition of "formatter" in the class Field.
-- Joe B. P.S. I need to start using the tools to generate diffs for proper patches. On Saturday, October 27, 2012 10:08:31 PM UTC-7, Massimo Di Pierro wrote: > > There are two issues here. One is that validators were originally intended > for form input and form input never submit None. They submit '' or missing > value but never None. I agree with you that you may want to call validators > and pass a None. In that case there is no need to ignore it. One problem > remains, will this break backward compatibility. Perhaps no. Not sure. > > Can you show your modifications to dal.py? > > On Saturday, 27 October 2012 17:48:54 UTC-5, Joe Barnhart wrote: >> >> But Massimo -- why do an early exit from "Field.formatter" if the value >> is None? Why not give the formatter object a chance to format None >> values? I just don't understand this decision. It is expedient for a >> small number of programs where the user doesn't want to format None, but at >> the expense of preventing anyone from ever formatting None. >> >> Your fix only papers over the problem by storing "NT" in the table >> instead of None. What if I want to show it as "N/T" later, or "no time"? >> I have to do a bulk change on the database just to accomplish a formatting >> task. There could be many reasons for wanting to format None into some >> other value -- all ignored because you chose to do an early exit in the >> formatter routine instead of passing the real value along. >> >> It is also not explained anywhere in the documentation that None will >> never be passed into the formatter, so it can't be a >> backwards-compatibility issue. >> >> -- Joe B. >> >> P.S. I'm perfectly happy to modify my version of dal.py forever, but I'm >> really interested in your reasoning for the early exit on None and if this >> pattern is carried out in other parts of web2py. >> >> On Saturday, October 27, 2012 12:44:21 PM UTC-7, Massimo Di Pierro wrote: >>> >>> You can do >>> >>> db.table.filter_in = lambda value: 'NT' is value is None else value >>> >>> >>> On Saturday, 27 October 2012 02:54:53 UTC-5, Joe Barnhart wrote: >>>> >>>> But Paolo -- you forgot the third option... >>>> >>>> FIX the problem in dal.py so that Validator classes work properly. It >>>> has no deleterious effects on other validators (at least so far in my >>>> testing) and it permits validators to format None values. >>>> >>>> -- Joe B. >>>> >>>> >>>>>>>>>> --