Larry White
2006-Apr-28 18:33 UTC
[Rails] 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/6a1085ca/attachment-0001.html
Michael Smedberg
2006-Apr-28 18:42 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
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. On 4/28/06, Larry White <ljw1001@gmail.com> wrote:> > 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. > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/3c8ac746/attachment.html
Larry White
2006-Apr-28 18:48 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
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 4/28/06, Michael Smedberg <smedberg@gmail.com> wrote:> > 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. > > On 4/28/06, Larry White <ljw1001@gmail.com> wrote: > > > 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. > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/22c9ae92/attachment.html
Tom Mornini
2006-Apr-28 18:54 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
On Apr 28, 2006, at 11:32 AM, Larry White wrote:> 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.change halt to breakpoint(self)> endand 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 Mornini
Larry White
2006-Apr-28 19:02 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
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. On 4/28/06, Tom Mornini <tmornini@infomania.com> wrote:> > On Apr 28, 2006, at 11:32 AM, Larry White wrote: > > > 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. > > 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 Mornini > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/056f8380/attachment.html
Michael Smedberg
2006-Apr-28 19:06 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
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... On 4/28/06, Larry White <ljw1001@gmail.com> wrote:> > 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 4/28/06, Michael Smedberg <smedberg@gmail.com> wrote: > > > > 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. > > > > On 4/28/06, Larry White < ljw1001@gmail.com> wrote: > > > > > 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. > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/3adc0809/attachment.html
Larry White
2006-Apr-28 19:25 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
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.). On 4/28/06, Michael Smedberg <smedberg@gmail.com> wrote:> > 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... > > > On 4/28/06, Larry White < ljw1001@gmail.com> wrote: > > > > 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 4/28/06, Michael Smedberg < smedberg@gmail.com> wrote: > > > > > > 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. > > > > > > On 4/28/06, Larry White < ljw1001@gmail.com> wrote: > > > > > > > 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. > > > > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/bac36b87/attachment.html
Larry White
2006-Apr-28 19:44 UTC
[Rails] Active Record save doesn''t save! (or throw an exception)
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?) On 4/28/06, Larry White <ljw1001@gmail.com> wrote:> > 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.). > > > On 4/28/06, Michael Smedberg <smedberg@gmail.com> wrote: > > > > 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... > > > > > > On 4/28/06, Larry White < ljw1001@gmail.com> wrote: > > > > > > 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 4/28/06, Michael Smedberg < smedberg@gmail.com> wrote: > > > > > > > > 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. > > > > > > > > On 4/28/06, Larry White < ljw1001@gmail.com> wrote: > > > > > > > > > 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. > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/1bb313d0/attachment.html