'validate_and_insert' throws error each time on latest version where it was fine before on prev version

92 views
Skip to first unread message

Jordan Ladora

unread,
Jun 1, 2017, 11:00:11 PM6/1/17
to web...@googlegroups.com
Hello,

I just belatedly upgraded from 8/9/15 (v2.12.2-stable) -> 5/10/16 (v2.14.6-stable) and have about 100 instances of 'validate_and_insert' in my application.

My app was previously (with 8/9/15 version) running these instances of 'validate_and_insert' A-OK but now, basically every instance of 'validate_and_insert' is throwing an error. When I use the shell I get a traceback that ends in:

if isinstance(value, (int, long)) or value.isdigit():
AttributeError: 'NoneType' object has no attribute 'isdigit'

It does this every single time I try to run 'validate_and_insert' when otherwise everything seems fine (and when I go back to the previous version and run the same exact code in the shell it goes fine).

If I change the 'validate_and_insert' to just 'insert' it works, but I'd like to keep the code the way it was before.. anyone else stumble on this or have a suggestion?

fyi it seems a little similar to the 5/8/17 thread "Validate_and_insert fails because "id" has no value" where he is also using 2.14.6-stable.

Thank you!

Anthony

unread,
Jun 2, 2017, 7:56:11 AM6/2/17
to web2py-users
How did you upgrade? Is it possible you did not upgrade PyDAL or get its proper version?

Anthony

Jordan Ladora

unread,
Jun 2, 2017, 10:27:16 AM6/2/17
to web2py-users
Hi Anthony,

Thanks for your response.

I didn't use the admin gui to upgrade but rather DL'd the new src zip and moved my app into it and then replaced all the files within the app that get upgraded (like static, languages, some of the views, etc.)

I just checked that everything has been upgraded, incl pydal.

-j

Anthony

unread,
Jun 2, 2017, 1:04:57 PM6/2/17
to web2py-users
Can we see the code and full traceback?

Jordan Ladora

unread,
Jun 3, 2017, 2:17:31 PM6/3/17
to web...@googlegroups.com
Yes, I was able to reproduce with a fresh install of web2py-

Here's what I did-
-------------------------------------------------------------------------------------
extracted new copy of web2py from DL src

modified welcome app-
 in models/db.py commented out this block-
  if not request.env.web2py_runtime_gae: / else:
 ..and replaced with-
   db = DAL('sqlite://storage.sqlite', lazy_tables=True, ignore_field_case=False, pool_size=10, check_reserved=['postgres', 'postgres_nonreserved'])

created models/db_data.py and added-

 db.define_table('datatable',
    Field('title', length=128),
    Field('name', requires=IS_IN_SET(['a','b','c'], multiple=False, zero=None), readable=False, writable=False, length=128),
    Field('dtype', requires=IS_IN_SET(['1','2','3'], multiple=False), label="Type", readable=False, writable=False, length=128),
    Field('finished', 'boolean', default=False, readable=False, writable=False),
    Field('the_timestamp', 'datetime', readable=False, writable=False),
    Field('alive', 'boolean', default=True, readable=False, writable=False),
    Field( 'comments', 'text' ),
    auth.signature, migrate=True,
    format = '%(title)s %(datatype)s %(species)s'
    )

created welcome/databases folder


------------

launched with-

python '.../web2py.py' -S welcome -M

>>> from datetime import datetime

## insert two fields-
>>> new_record = db.datatable.validate_and_insert(dtype='1', the_timestamp=datetime.utcnow())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".../gluon/packages/dal/pydal/objects.py", line 749, in validate_and_insert
    response, new_fields = self._validate_fields(fields)
  File ".../gluon/packages/dal/pydal/objects.py", line 741, in _validate_fields
    value, error = self[fieldname].validate(raw_value)
  File ".../gluon/packages/dal/pydal/objects.py", line 1634, in validate
    (value, error) = validator(value)
  File ".../gluon/validators.py", line 660, in __call__

    if isinstance(value, (int, long)) or value.isdigit():
AttributeError: 'NoneType' object has no attribute 'isdigit'


## no fields-
>>> new_record = db.datatable.validate_and_insert()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".../gluon/packages/dal/pydal/objects.py", line 749, in validate_and_insert
    response, new_fields = self._validate_fields(fields)
  File ".../gluon/packages/dal/pydal/objects.py", line 741, in _validate_fields
    value, error = self[fieldname].validate(raw_value)
  File ".../gluon/packages/dal/pydal/objects.py", line 1634, in validate
    (value, error) = validator(value)
  File ".../gluon/validators.py", line 660, in __call__

    if isinstance(value, (int, long)) or value.isdigit():
AttributeError: 'NoneType' object has no attribute 'isdigit'


## 'name' field here should throw error for not being in set defined by model-
>>> new_record = db.datatable.validate_and_insert(title='test title', name='test name', dtype='1', finished=False, the_timestamp=datetime.utcnow(), alive=True, comments='this is a test')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".../gluon/packages/dal/pydal/objects.py", line 749, in validate_and_insert
    response, new_fields = self._validate_fields(fields)
  File ".../gluon/packages/dal/pydal/objects.py", line 741, in _validate_fields
    value, error = self[fieldname].validate(raw_value)
  File ".../gluon/packages/dal/pydal/objects.py", line 1634, in validate
    (value, error) = validator(value)
  File ".../gluon/validators.py", line 660, in __call__

    if isinstance(value, (int, long)) or value.isdigit():
AttributeError: 'NoneType' object has no attribute 'isdigit'


## all fields-
>>> new_record = db.datatable.validate_and_insert(title='test title', name='a', dtype='1', finished=False, the_timestamp=datetime.utcnow(), alive=True, comments='this is a test')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".../gluon/packages/dal/pydal/objects.py", line 749, in validate_and_insert
    response, new_fields = self._validate_fields(fields)
  File ".../gluon/packages/dal/pydal/objects.py", line 741, in _validate_fields
    value, error = self[fieldname].validate(raw_value)
  File ".../gluon/packages/dal/pydal/objects.py", line 1634, in validate
    (value, error) = validator(value)
  File ".../gluon/validators.py", line 660, in __call__

    if isinstance(value, (int, long)) or value.isdigit():
AttributeError: 'NoneType' object has no attribute 'isdigit'


Thanks again for your help.



On Fri, Jun 2, 2017 at 11:04 AM, Anthony <abas...@gmail.com> wrote:
Can we see the code and full traceback?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/Cqz5GbP07F0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Jun 5, 2017, 12:19:52 PM6/5/17
to web2py-users
The problem is that you have auth.signature but are doing inserts without a logged in user. As a result, the values of the created_by and modified_by fields are None but are required to be id's from the db.auth_user table. This should simply result in a failed validation rather than an exception, but the IS_IN_DB validator breaks when None values are passed in for id or integer fields (I would consider it a bug).

Anthony

Jordan Ladora

unread,
Jun 5, 2017, 12:32:09 PM6/5/17
to web...@googlegroups.com
Thanks. It's also throwing the identical error when using the app's web page as a logged in user.

Suggestions?

Anthony

unread,
Jun 5, 2017, 12:43:16 PM6/5/17
to web2py-users
On Monday, June 5, 2017 at 12:32:09 PM UTC-4, Jordan Ladora wrote:
Thanks. It's also throwing the identical error when using the app's web page as a logged in user.

Are you sure? I tried it as a logged in user and it works fine (using your exact table definition and insert code).

Anthony

Jordan Ladora

unread,
Jun 6, 2017, 4:41:56 PM6/6/17
to web2py-users
Thank you for checking that.

Yeah, I'm still getting this, even when logged in. As a temp workaround I swapped all the instances of "validate_and_insert" in my app for "insert".

I did find a note I made a couple years ago from back before I upgraded to the latest version that said validate_and_insert would not work if no fields were set, like in the '## no fields-' example I posted on 6/3, so maybe this is due to something else I have e.g. in db.py...

Jordan Ladora

unread,
Sep 21, 2017, 1:19:35 PM9/21/17
to web2py-users
My bad - I was confused there. Forgot to post this earlier, but you were totally right; it's only happening when not logged in.

Thanks again for your patience & help.

-j
Reply all
Reply to author
Forward
0 new messages