Hello,
I am trying to use validate_and_insert(), but fail to use it... I am not sure if it a kind of bug, but let me explain the use case so you can reproduce the error and confirm or reject this possibility...
I don't want to blame any one, but my code fail on this line introduce 2 years ago :
https://github.com/web2py/web2py/blame/master/gluon/validators.py#L636Full code here :
https://github.com/web2py/web2py/blob/fb4c114d85494ad6d79d69539adaae103d76e5ce/gluon/validators.py#L636USE CASE
Need a table with an integer field not mandatory :
db.define_table('dummy_table',
Field('field1', 'string'),
Field('field2', 'integer', requires=IS_EMPTY_OR(IS_INT_IN_RANGE(0, 100)))
So, I expect not having and error nor an AttributeError: 'NoneType' object has no attribute 'isdigit' (which is even more problematic it prevent me to do a legitimate operation) if I do :
db.dummy_table.validate_and_insert(field1='some_string')
I have web2py 2.14.6, but the piece of code triggering the error seems unchange, so I expect the issue I face to be present in the last web2py version too, but I didn't tested it yet...
I had look on pyDAL side but can see a lead there...
What I do understand of the situation is that web2py enforce that any id or interger field (I guess I would be ok with the former but the later doesn't make sens to me) be actually an int in any possible way and prevent an integer field to be empty or None, which you may would like to be empty depending of your database design...
Do I am right?? And should this piece of code be refactored in order that an integer field could be None?? The issue seems to be related to the fact to the usage of isdigit that is a string method and fail on a None...
I am not sure what would be the best way to fix that in case it is actually a bug without introduce any security issue or bug for other use case that would had required this check to be wrote that way.
Thanks
Richard