Help: Timestamp and Userstamp just stopped working

Uh oh. I am going to have a nightmare cleaning this up… It looks
like timestamp and userstamp just stopped doing their thing.

Across several different models, I am seeing NULLs in my database for
updated_by and updated_at and created_at/etc.

Last night, I ran a migration that turned userstamp and timestamp off
for two different models using the class attribute accessor. I have
since restarted the production server so there should be no lasting
effect from this. This problem is affecting models which had nothing to
do with the migration.

Has anyone heard of something like this? I shudder to think of the mess
this will create in my database today – a Monday – our heaviest day.
I will have 500+ users through the site today plus my staff working on
content all day. Ugh.

Any ideas where to look? I looked at the source for both of these and
they are so simple I don’t see how they would just break like that.

Steven

Steven Talcott S. wrote:

Uh oh. I am going to have a nightmare cleaning this up… It looks
like timestamp and userstamp just stopped doing their thing.

Across several different models, I am seeing NULLs in my database for
updated_by and updated_at and created_at/etc.

Okay, Lesson Learned!

Class attribute accessors can be called on an instance.

Do not call my_model.record_timestamps = false unless you want to turn
this behavior off system-wide.

Two things:

  1. the documentation on Timestamp should explain more clearly that
    setting applies to ActiveRecord::Base… not the class of your model and
    certainly not the instance.

  2. I think this violates the “do the expected thing” principle. Does
    anyone agree?

Thank goodness for open source. I was able to contain the damage once I
saw the problem and removed the offending line from my code.

May google save this and help someone else to avoid the same problem.
Now, to clean up those NULLs…

Best,

Steven

Steven Talcott S. wrote:

Do not call my_model.record_timestamps = false unless you want to turn
this behavior off system-wide.

Interesting. What you want should certainly be possible.

This is what I found in the documentation
(http://caboo.se/doc/classes/ActiveRecord/Timestamp.html):

{snip}
Keep in mind that, via inheritance, you can turn off timestamps on a
per model basis by setting record_timestamps to false in the desired
models.

class Feed < ActiveRecord::Base
self.record_timestamps = false
# …
end
{snip}

Try doing this and see if it helps (on your development box :slight_smile:

I’m not sure why doing “self.” would be different from what you did,
though…?

Jeff

Jeff C. wrote:

Steven Talcott S. wrote:

Do not call my_model.record_timestamps = false unless you want to turn
this behavior off system-wide.

Interesting. What you want should certainly be possible.

I’m not sure why doing “self.” would be different from what you did,
though…?

I need to read up on the subtleties of “self.” since I am unclear on the
implications. I have used it inconsistently in my code so far. Any
good pointers? I will check pickaxe tomorrow.

Steven

What ended up working for me was this:

class Weird < ActiveRecord::Base
def self.record_timestamps; false; end
end

Hope it helps,

AEM

On 9/11/06, Jeff [email protected] wrote:


Adrian Esteban Madrid

On 9/11/06, Steven Talcott S. [email protected]
wrote:

though…?

I need to read up on the subtleties of “self.” since I am unclear on the
implications. I have used it inconsistently in my code so far. Any
good pointers? I will check pickaxe tomorrow.

The best coverage of that topic that I’ve seen so far has been in Ruby
for Rails.

– James