Larry White
2006-Apr-28 20:06 UTC
[Rails] Active Record save doesn''t save! (more detail - is this a bug?)
I got it to work by changing scheduled_end_date= nil to self.scheduled_end_date= nil. I believe these statements should be equivilent. I don''t know Ruby/Rails well enough to know when, if or why that should matter. Can someone educate me please? I want to believe this framework is ready for production work, but silently dropping data is a very big problem. I expect that I''ve done something wrong. I just want to know what. On 4/28/06, Larry White <ljw1001@gmail.com> wrote:> > 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/3e3762fa/attachment-0001.html
Chris T
2006-Apr-28 22:10 UTC
[Rails] Active Record save doesn''t save! (more detail - is this a bug?)
Only a roob noob but just read the bit about self and scope in the excellent Ruby for Rails and I believe self.somemethod can be written as somemethod *except* when followed by an assignment (i.e. equals sign). Ruby thinks somemethod= nil is assigning the value (in this case nil) to a local variable, somemethod. Hope this helps Larry White wrote:> I got it to work by changing > > scheduled_end_date= nil > to > self.scheduled_end_date= nil. > > I believe these statements should be equivilent. > > I don''t know Ruby/Rails well enough to know when, if or why that > should matter. Can someone educate me please? I want to believe this > framework is ready for production work, but silently dropping data is > a very big problem. I expect that I''ve done something wrong. I just > want to know what. > > > On 4/28/06, *Larry White* <ljw1001@gmail.com > <mailto:ljw1001@gmail.com>> wrote: > > 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 > <mailto: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 > <mailto: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 > <mailto: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 > <mailto: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 > <mailto: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 <http://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 > <mailto:Rails@lists.rubyonrails.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > <mailto:Rails@lists.rubyonrails.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > <mailto:Rails@lists.rubyonrails.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > <mailto: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 >
Larry White
2006-Apr-29 00:05 UTC
[Rails] Active Record save doesn''t save! (more detail - is this a bug?)
On 4/28/06, Chris T <ctmailinglists@googlemail.com> wrote:> > Only a roob noob but just read the bit about self and scope in the > excellent Ruby for Rails and I believe self.somemethod can be written as > somemethod *except* when followed by an assignment (i.e. equals sign). > Ruby thinks somemethod= nil is assigning the value (in this case nil) to > a local variable, somemethod. > > Hope this helpsI guess you''re right. The lack of a requirement to declare variables is hard to get used to, especially when I can only do Ruby part time. Thanks. Time for a code review, I guess. I need to get that book, everybody says it rocks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060429/18c1a38f/attachment.html