noooope!
validate_and_update is a method of a Query, not of a Table! (you may have
scrambled it with validate_and_insert()...)
What you need to do is
db(db.uperson.auth_user==1).validate_and_update(age=101)
On Monday, May 30, 2016 at 3:34:48 PM UTC+2, Pierre wrote:
>
> Hi,
>
> here it is : the cruel reality as is :(
>
> (1) the table:
>
> db.define_table('uperson',
> Field('auth_user','reference auth_user',unique=True,requires
> = IS_NOT_IN_DB(db,'uperson.auth_user')),
> Field('country'),
> Field('age','integer'))
>
>
>
> (2) the actions:
>
> >>> db.uperson.insert(auth_user=1,age=100,country='fr')
> 1L
> >>> db.commit()
> >>> r = db.uperson.validate_and_update(db.uperson.auth_user==1,age=101)
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "/opt/web2py/gluon/packages/dal/pydal/objects.py", line 741, in
> validate_and_update
> response, new_fields = self._validate_fields(fields, 'update')
> File "/opt/web2py/gluon/packages/dal/pydal/objects.py", line 727, in
> _validate_fields
> value, error = self[fieldname].validate(raw_value)
> File "/opt/web2py/gluon/packages/dal/pydal/objects.py", line 1625, in
> validate
> (value, error) = validator(value)
> File "/opt/web2py/gluon/validators.py", line 696, in __call__
> row = subset.select(table._id, field, limitby=(0, 1),
> orderby_on_limitby=False).first()
> File "/opt/web2py/gluon/packages/dal/pydal/objects.py", line 2002, in
> select
> return adapter.select(self.query,fields,attributes)
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/sqlite.py", line 122
> , in select
> return super(SQLiteAdapter, self).select(query, fields, attributes)
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/base.py", line 1273,
> in select
> sql = self._select(query, fields, attributes)
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/base.py", line 1160,
> in _select
> sql_w = ' WHERE ' + self.expand(query) if query else ''
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/base.py", line 945,
> in expand
> rv = op(first, second, **optional_args)
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/base.py", line 839,
> in EQ
> self.expand(second, first.type))
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/base.py", line 955,
> in expand
> rv = self.represent(expression, field_type)
> File "/opt/web2py/gluon/packages/dal/pydal/adapters/base.py", line 1432,
> in represent
> return str(long(obj))
> ValueError: invalid literal for long() with base 10: 'None'
>
> second attempt:
>
> >>> db.uperson.validate_and_update(db.uperson.auth_user==1,auth_user=1,age
> =102)
> <Row {'errors': {'auth_user': 'Value already in database or empty'}, 'id':
> None}
>
>
>
>
--
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 the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.