Issues with record versioning

133 views
Skip to first unread message

Ricardo Oliveira

unread,
Dec 21, 2016, 11:13:17 PM12/21/16
to web2py-users
Hi,
I'm having a couple of issues with record versioning:
1) I had to directly "force" versioning for tables (db.mytable._enable_record_versioning() for each table), although I have:

     auth.define_tables(username=True, signature=True)
     auth.enable_record_versioning(db, archive_names='%(tablename)s_archive', current_record='current_record')
     db._common_fields.append(auth.signature)

2) the user & time are not recorded on the modified_on, modified_by columns

Not sure where to go from here.
I would appreciate any help.

Best regards,
Ricardo.

Ricardo Oliveira

unread,
Dec 23, 2016, 11:49:13 AM12/23/16
to web2py-users
Hi,

I was able to fix problem 1).
Turns out that auth.enable_record_versioning needs to be after all the define_tables (found the answer on another post, but couldn't find it in the docs).

Still having issue 2). Has anyone seen this before? The solutions I saw on other posts didn't work for me.

Thanks.

Anthony

unread,
Dec 23, 2016, 5:40:01 PM12/23/16
to web2py-users
2) the user & time are not recorded on the modified_on, modified_by columns

How are you creating/updating the records?

Ricardo Oliveira

unread,
Jan 4, 2017, 6:01:36 AM1/4/17
to web2py-users
Hi Anthony,

Thanks for your reply.
I'm using the DAL's insert method for the creation. Eg:

db.table_x.insert(name='something')

For updates, I get the rows from the table first, change the values on the row object and then use the update_record() method for updating. Eg:

record = db(db.table_x.id == row_id).select().first()
record['name'] = 'something else'
record.update_record()


Thanks.
Ricardo.

Áureo Dias Neto

unread,
Jan 4, 2017, 6:06:05 AM1/4/17
to web...@googlegroups.com
Hello,

You can do this, for update
db(db.person.id==1).update(name='Tim')

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ricardo Oliveira

unread,
Jan 4, 2017, 6:51:36 AM1/4/17
to web2py-users
Thanks Áureo, good to know!

I use the other format because I do a few checks before doing the update, to see if the data is valid, but this short notation will no doubt be helpful in the future :)

Ricardo.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

黄祥

unread,
Jan 4, 2017, 9:30:40 AM1/4/17
to web2py-users
have the same situation but work fine, modified_on and modified_by is updated on the table. 
not sure why update_record on your side is not work.

best regards,
stifan

Ricardo Oliveira

unread,
Jan 9, 2017, 10:45:59 AM1/9/17
to web2py-users
I activated query logging but the only thing I can see is that when a change is made, the insert in the archive table has both the values (modified_on, modified_by) set to NULL.
Anyone else have any other ideas?
How can I further troubleshoot this issue?

TIA,
Ricardo.

Anthony

unread,
Jan 9, 2017, 5:10:23 PM1/9/17
to web2py-users
record = db(db.table_x.id == row_id).select().first()
record['name'] = 'something else'
record.update_record()

That's the one way you cannot do it. The problem is when you call .update_record() with no arguments, it takes all the existing fields in the record and uses them in the database update. It will therefore use the existing values of modified_by and modified_on. Typically, modified_by and modified_on get updated because they are excluded from the update call, which prompts the DAL to fill their values in automatically. But this mechanism breaks down when calling .update_record() with no arguments. We should probably add a note about this in the book.

Anthony

Ricardo Oliveira

unread,
Jan 10, 2017, 6:43:27 AM1/10/17
to web2py-users
Ah.. that should explain it then. In that case I'll have to do an update call with each of the update fields named individually.
That would be something nice to have in the book, I agree :)

Thanks Anthony, I'm going to test it now.

Ricardo Oliveira

unread,
Jan 17, 2017, 5:18:39 AM1/17/17
to web2py-users
Hi,
Just so it's clear for anyone having the same issue, Anthony's tip was right on target. All is working now.
Conclusion: you must use the update_record(field=new_value) format if you're using authentication, and not the update_record() format.

Thanks again to all that chipped in and Anthony for the solution.

Ricardo.
Reply all
Reply to author
Forward
0 new messages