OK - I think I have the answer. I discovered it wasn't table-specific, it worked with this same method / table elsewhere in the app. The place it was failing was using bulk_insert. I changed to insert individually and all works fine.
Bug? On Friday, May 29, 2015 at 6:39:56 AM UTC+2, Ian Ryder wrote: > > Hi, the key point is I'm not getting passed a dict, I'm getting passed a > list. Here's a dump of what the _is_before handler gets passed: > > [(<pydal.objects.Field object at 0x11eb9ad10>, datetime.datetime(2015, 5, > 29, 6, 32, 27, 732420)), (<pydal.objects.Field object at 0x1334a5150>, 1L > ), (<pydal.objects.Field object at 0x1334a5290>, 8L), (<pydal.objects. > Field object at 0x1334a5390>, 2L), (<pydal.objects.Field object at > 0x11c2dfcd0>, 5.0), (<pydal.objects.Field object at 0x1334a57d0>, 14093L), > (<pydal.objects.Field object at 0x1334a5b10>, 'APPEAL'), (<pydal.objects. > Field object at 0x1334a5050>, 1L), (<pydal.objects.Field object at > 0x1334a5410>, 358001L), (<pydal.objects.Field object at 0x11eb9a4d0>, > datetime.datetime(2015, 5, 29, 6, 32, 27, 732420)), (<pydal.objects.Field > object at 0x1334a53d0>, 5.0), (<pydal.objects.Field object at 0x1334a5690 > >, True), (<pydal.objects.Field object at 0x1334a55d0>, 1L)] > > I test it on a different table and it gets a dict as expected: > {'query_group': 1, 'name': 'asddasdasdasdsada', 'created_date': datetime. > datetime(2015, 5, 29, 6, 27, 37, 2291), 'run_order': 0, 'type': '', > 'sum_description': '', 'created_by': 1L} > > I'll post again the definition for the one that isn't working: > db.income_line_item._before_insert.append(lambda f: > trigger_ili_before_insert(f)) > > Which is essentially the same for the one that is working: > db.query._before_insert.append(lambda f: query_before_test(f)) > > > > > On Thursday, May 28, 2015 at 11:10:21 PM UTC+2, Niphlod wrote: >> >> the book shows how to print every argument passed to those functions.... >> I dunno how to make the book clearer :°°°D >> >> >> before_insert .... >> >> >> def this_is_before_insert(some_dict): >> if 'last_name' in some_dict: >> some_dict['last_name'] = 'altering' + some_dict['last_name'] >> >> db.auth_user._before_insert.append(lambda f: this_is_before_insert(f)) >> >> >>>db.auth_user.insert(first_name='john') >> 1L >> >>> db.auth_user.insert(last_name='doe') >> 2L >> >>> rtn = db(db.auth_user.id>0).select(db.auth_user.first_name, db. >> auth_user.last_name) >> >>> print str(rtn) >> auth_user.first_name,auth_user.last_name >> john, >> ,alteringdoe >> >> before_update ... >> >> def this_is_before_update(a_set, some_dict): >> if 'last_name' in some_dict: >> some_dict['last_name'] += 'was_updated' >> >> db.auth_user._before_update.append(lambda s,f: this_is_before_update(s,f >> )) >> >> >>> db.auth_user.insert(first_name='john', last_name='doe') >> 1L >> >>> db(db.auth_user.first_name=='john').update(last_name='white') >> 1 >> >>> rtn = db(db.auth_user.id>0).select(db.auth_user.first_name, db. >> auth_user.last_name) >> >>> print str(rtn) >> auth_user.first_name,auth_user.last_name >> john,whitewas_updated >> >> >> >> >> >> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.