Forum: Ruby on Rails inserted_at seems buggy in production mode?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jeroen H. (Guest)
on 2006-03-16 13:37
(Received via mailing list)
Hi,

I've got a table with an inserted_at column. When I insert a record it
automatically injects the current date/time, all is well.
Then when I insert a second record, it uses the exact same timestamp
that is used in the first record.

This behavior only seems to occur in production mode. When I restart the
server, the problem goes away but then immidetatly occurs again on the
second insert. I'm using postgresql 8.1 and I have my default value for
the inserted_at column set to now().

Any ideas??

Jeroen


--- below is some log output ----

Processing MatchController#comment (for 192.87.30.169 at 2006-03-16
12:23:41) [POST]
   Parameters: {"mc"=>{"body"=>"testtest"}, "commit"=>"Een moment ...",
"action"=>"comment", "id"=>"159", "controller"=>"match"}
   Match Load (0.001001)   SELECT * FROM matches WHERE (matches.id =
'159') LIMIT 1
   SQL (0.000319)   BEGIN
   PK and serial sequence (0.017476)    SELECT attr.attname,
name.nspname, seq.relname
  FROM pg_class seq,
  pg_attribute attr,
  pg_depend dep,
  pg_namespace name,
  pg_constraint cons
  WHERE seq.oid = dep.objid
  AND seq.relnamespace = name.oid
  AND seq.relkind = 'S'
  AND attr.attrelid = dep.refobjid
  AND attr.attnum = dep.refobjsubid
  AND attr.attrelid = cons.conrelid
  AND attr.attnum = cons.conkey[1]
  AND cons.contype = 'p'
  AND dep.refobjid = 'match_comments'::regclass

   MatchComment Create (0.002280)   INSERT INTO match_comments ("body",
"match_id", "player_id", "inserted_at") VALUES('testtest', 159, 14,
'2006-03-16 12:22:55')
   SQL (0.000684)   SELECT currval('public.match_comments_id_seq')
   SQL (0.034973)   COMMIT
Redirected to http://tcuithof.laddertennis.nl/match/show/159


Processing MatchController#comment (for 192.87.30.169 at 2006-03-16
12:24:57) [POST]
   Parameters: {"mc"=>{"body"=>"test"}, "commit"=>"Een moment ...",
"action"=>"comment", "id"=>"159", "controller"=>"match"}
   Match Load (0.001003)   SELECT * FROM matches WHERE (matches.id =
'159') LIMIT 1
   SQL (0.000327)   BEGIN
   MatchComment Create (0.000929)   INSERT INTO match_comments ("body",
"match_id", "player_id", "inserted_at") VALUES('test', 159, 14,
'2006-03-16 12:22:55')
   SQL (0.000448)   SELECT currval('public.match_comments_id_seq')
   SQL (0.036623)   COMMIT


Processing MatchController#comment (for 192.87.30.169 at 2006-03-16
12:26:00) [POST]
   Parameters: {"mc"=>{"body"=>"dsasda"}, "commit"=>"Een moment ...",
"action"=>"comment", "id"=>"159", "controller"=>"match"}
   Match Load (0.001013)   SELECT * FROM matches WHERE (matches.id =
'159') LIMIT 1
   SQL (0.000307)   BEGIN
   MatchComment Create (0.000991)   INSERT INTO match_comments ("body",
"match_id", "player_id", "inserted_at") VALUES('dsasda', 159, 14,
'2006-03-16 12:22:55')
   SQL (0.000462)   SELECT currval('public.match_comments_id_seq')
   SQL (0.034870)   COMMIT
Jeroen H. (Guest)
on 2006-03-16 13:46
(Received via mailing list)
Jeroen H. wrote:
> Hi,
>
> I've got a table with an inserted_at column. When I insert a record it
> automatically injects the current date/time, all is well.
> Then when I insert a second record, it uses the exact same timestamp
> that is used in the first record.

Okay I should have searched for this before I posted
http://dev.rubyonrails.org/ticket/2257

More logic to move out of the database. I may as well start using
SQLite! ;-)

Jeroen
Lugovoi N. (Guest)
on 2006-03-16 13:47
(Received via mailing list)
I think your problem is related to this ticket:
http://dev.rubyonrails.org/ticket/2257
In production mode default value is cached right after the first query
for table columns metadata, so it will be the same on subsequent
requests.

You could rename 'inserted_at' to 'created_at' and use Rails magic of
ActiveRecord::Timestamp mixin (active_record/timestamp.rb)
Jeroen H. (Guest)
on 2006-03-16 13:59
(Received via mailing list)
Lugovoi N. wrote:
> I think your problem is related to this ticket:
> http://dev.rubyonrails.org/ticket/2257
> In production mode default value is cached right after the first query
> for table columns metadata, so it will be the same on subsequent
> requests.
>
> You could rename 'inserted_at' to 'created_at' and use Rails magic of
> ActiveRecord::Timestamp mixin (active_record/timestamp.rb)

Thanks!

Aha I thought it should be called inserted_at, but created_at is the
special column name. My bad!

So if I do that, what should I use as my column definition? NOT NULL?
And no default value?

Jeroen
This topic is locked and can not be replied to.