Active Record save doesn't save! (or throw an exception)

PLEASE help me - this is making me insane.

Can anyone suggest any reasons for this behavior? It occured
previously,
then went away and is now back.

In Task.rb (where task is an active record subclass)

def clear_schedule
    puts "clearing schedule for task"
    scheduled_end_date= nil                          #reset the

scheduled end date
save
halt. #this
makes
execution stop with an error.
end

This is the console output this produces:

clearing schedule for task
127.0.0.1 - - [28/Apr/2006:13:44:01 Eastern Daylight Time] “POST
/tasks/update/1
06 HTTP/1.1” 500 10736
http://localhost:3000/tasks/edit/106 → /tasks/update/106

When I query the db, scheduled_end_date is still set to a valid date,
even
though in the model I set it to nil, called save and then stopped.
There
were no exceptions other than this:

undefined local variable or method `halt’ for #Task:0x3a23328

I sometimes have the opposite problem in a related piece of code for
this
same object/column (I set it to a real value, save it, retrieve the
object
from the database in the very next line of code. When I check the value
it’s
nil.)

Can someone tell me what the expected behavior is within a transaction
versus outside of a transaction? The behavior seems unpredictable in
both
situations but I’m not sure. I assumed that if I was inside a
transaction
that I would still see the new value. All of this occurs within a
single
http request so I assumed that all the data access was on the same
connection.

Anyway, I’m stumped and resolving this is critical to my project.
Please
help if you can.

You might want to use the “save!” method, instead of “save”. The former
will throw an exception if there are problems, the latter will simply
return
false. You can catch the exception and look at it to see what’s really
going on.

I just tried that - (also wrapped the call with an if )

 if (save!)
  puts "I SAVED IT with !!!!"
else
  puts "THE SAVE FAILED"
end

It outputs “I SAVED IT …” to the console but still the db record
contains
a real value not nil when the program stops on the next line.

On Apr 28, 2006, at 11:32 AM, Larry W. wrote:

scheduled end date
save
halt. #this
makes execution stop with an error.

change halt to

breakpoint(self)

end

and then type:

script/breakpointer

before hitting the page. It will show an “error” that said there’s
nothing to breakpoint, which is normal, because no code is in a
breakpoint yet.

When you hit the page, the browser will freeze, and the breakpointer
will come alive, and show you the Task object.

Take a look at the @errors attribute.


– Tom M.

Thank you. I tried that and got @erros={}

but I just looked In my Postgres logs and noticed that I’m getting this
error message -

Unexpected EOF on client connection.

The write is not happening at all. I’ve got optimistic locking on and
the
lock-version field did not update so the problem isn’t with an
individual
setter (though I had that problem with this same code a couple months
ago. I
assumed originally that it was back.).

OK, so it sounds like the save is happening successfully. Do you know
what
it’s doing? I’d look at the log file, to see what SQL is happening. If
there’s no SQL changing the data, then the problem is with your Ruby
code (
e.g. maybe you overrode the “scheduled_end_date=” method or something.)
If
the SQL is being run, then check the DB- make sure the SQL is successful
(though it’s not obvious why it wouldn’t be.) If the data is in the DB,
then the problem is with reading it, not with the save.

I know- these are just general suggestions, not a solution, but I hope
it’s
a start…

My mistake - i was looking at the wrong task record. The record is
getting
saved, but the scheduled_end_date field is not getting updated. Since
my
task object doesn’t have scheduled_end_date over-written (any more),
what
else could cause that? Something weird seems to be going on in the db
mapping.

Does anyone know if there are any known issues supporting the Postgres
timestamptz type?)