I followed the upgrade procedures from .85 to .9. Now I am getting some strange behavior. In my controller I have a @photo = Photo.find(@request[''id'']) URL is http://hostname/photos/show/13113 and in the template trace, I verified that @request[''id''] is indeed 13113 (see below), in the logs/development.log file I see this SQL query being run though: SELECT * FROM photos WHERE id = ''--- \"13113\"'' so of course I am getting the error: ActiveRecord::RecordNotFound in Photos#show Couldn''t find Photo with ID = 13113 /app/controllers/photos_controller.rb:16:in `show'' here is my request: Request Parameters: {"site_id"=>"1", "id"=>"13113"} Why in the world is id set to ''-- \"13113\"''? Thanks!
Just an update, I tried it again under the new breakpoint/debugger (which rocks!) and here is what I got (same problem): irb(#<PhotosController:0xb734c488>):006:0> @request[''id''] => "13113" irb(#<PhotosController:0xb734c488>):007:0> @photo Photo.find(@request[''id'']) ActiveRecord::RecordNotFound: Couldn''t find Photo with ID = 13113 And, again, this is in the logs: Photo Find (0.001364) SELECT * FROM photos WHERE id = ''--- \"13113\"'' Sean Leach wrote:> I followed the upgrade procedures from .85 to .9. Now I am getting some > strange behavior. In my controller I have a > > @photo = Photo.find(@request[''id'']) > > URL is > > http://hostname/photos/show/13113 > > and in the template trace, I verified that @request[''id''] is indeed > 13113 (see below), in the logs/development.log file I see this SQL query > being run though: > > SELECT * FROM photos WHERE id = ''--- \"13113\"'' > > so of course I am getting the error: > > > ActiveRecord::RecordNotFound in Photos#show > > Couldn''t find Photo with ID = 13113 > > /app/controllers/photos_controller.rb:16:in `show'' > > here is my request: > > Request > > Parameters: {"site_id"=>"1", "id"=>"13113"} > > Why in the world is id set to ''-- \"13113\"''? > > Thanks! > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Ok found the problem, but no idea what to do. I put breakpoints within active_record/connection_adaptors/abstract_adaptor.rb (did I mention the debugger absolutely rocks), and here is the problem. When quote_string is called in abstract_adaptor, value.class is CGI::QueryExtension::Value, so it falls to the final case in this statement: case value when String then "''#{quote_string(value)}''" # '' (for ruby-mode) when NilClass then "NULL" when TrueClass then (column && column.type =:boolean ? "''t''" : "1") when FalseClass then (column && column.type =:boolean ? "''f''" : "0") when Float, Fixnum, Bignum then value.to_s when Date then "''#{value.to_s}''" when Time, DateTime then "''#{value.strftime("%Y-%m-%d %H:%M:%S")}''" else "''#{quote_string(value.to_yaml)}''" end and value.to_yaml comes out as you see below. Do we all of a sudden need to typecase the parameters to find to strings? irb(#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7345ae8>):005:0> value => "13113" irb(#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7345ae8>):006:0> value.class => CGI::QueryExtension::Value irb(#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7345ae8>):007:0> value.to_yaml => "--- \"13113\"" Sean Leach wrote:> Just an update, I tried it again under the new breakpoint/debugger > (which rocks!) > > and here is what I got (same problem): > > irb(#<PhotosController:0xb734c488>):006:0> @request[''id''] > => "13113" > irb(#<PhotosController:0xb734c488>):007:0> @photo > Photo.find(@request[''id'']) > ActiveRecord::RecordNotFound: Couldn''t find Photo with ID = 13113 > > And, again, this is in the logs: > > Photo Find (0.001364) SELECT * FROM photos WHERE id = ''--- \"13113\"'' > > > > > Sean Leach wrote: >> I followed the upgrade procedures from .85 to .9. Now I am getting some >> strange behavior. In my controller I have a >> >> @photo = Photo.find(@request[''id'']) >> >> URL is >> >> http://hostname/photos/show/13113 >> >> and in the template trace, I verified that @request[''id''] is indeed >> 13113 (see below), in the logs/development.log file I see this SQL query >> being run though: >> >> SELECT * FROM photos WHERE id = ''--- \"13113\"'' >> >> so of course I am getting the error: >> >> >> ActiveRecord::RecordNotFound in Photos#show >> >> Couldn''t find Photo with ID = 13113 >> >> /app/controllers/photos_controller.rb:16:in `show'' >> >> here is my request: >> >> Request >> >> Parameters: {"site_id"=>"1", "id"=>"13113"} >> >> Why in the world is id set to ''-- \"13113\"''? >> >> Thanks! >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> else "''#{quote_string(value.to_yaml)}''"which should be "''#{quote_string(value)}''" i guess. What you get is yaml output which is prolly not what you want. -- Sascha Ebach
On Thu, 16 Dec 2004 15:54:20 -0800, Sean Leach <sleach-IaTyVoCi2nzQT0dZR+AlfA@public.gmane.org> wrote:> Ok found the problem, but no idea what to do. I put breakpoints within > active_record/connection_adaptors/abstract_adaptor.rb (did I mention the > debugger absolutely rocks), and here is the problem. > > When quote_string is called in abstract_adaptor, value.class is > CGI::QueryExtension::Value, so it falls to the final case in this statement:Hmm, I''ve been running edge rails for a while, and my application does exactly what yours does and everything still works. Unfortunately I''m away from my system right now so I can''t see if it''s broken with 0.9. In the meantime, if your id is an int, use .to_i. Can anyone else reproduce? This seems like a pretty big problem.> case value > when String then "''#{quote_string(value)}''" # '' > (for ruby-mode) > when NilClass then "NULL" > when TrueClass then (column && column.type => :boolean ? "''t''" : "1") > when FalseClass then (column && column.type => :boolean ? "''f''" : "0") > when Float, Fixnum, Bignum then value.to_s > when Date then "''#{value.to_s}''" > when Time, DateTime then "''#{value.strftime("%Y-%m-%d > %H:%M:%S")}''" > else "''#{quote_string(value.to_yaml)}''" > end > > and value.to_yaml comes out as you see below. Do we all of a sudden > need to typecase the parameters to find to strings? > > irb(#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7345ae8>):005:0> > value > => "13113" > irb(#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7345ae8>):006:0> > value.class > => CGI::QueryExtension::Value > irb(#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7345ae8>):007:0> > value.to_yaml > => "--- \"13113\"" > > > Sean Leach wrote: > > Just an update, I tried it again under the new breakpoint/debugger > > (which rocks!) > > > > and here is what I got (same problem): > > > > irb(#<PhotosController:0xb734c488>):006:0> @request[''id''] > > => "13113" > > irb(#<PhotosController:0xb734c488>):007:0> @photo > > Photo.find(@request[''id'']) > > ActiveRecord::RecordNotFound: Couldn''t find Photo with ID = 13113 > > > > And, again, this is in the logs: > > > > Photo Find (0.001364) SELECT * FROM photos WHERE id = ''--- \"13113\"'' > > > > > > > > > > Sean Leach wrote: > >> I followed the upgrade procedures from .85 to .9. Now I am getting some > >> strange behavior. In my controller I have a > >> > >> @photo = Photo.find(@request[''id'']) > >> > >> URL is > >> > >> http://hostname/photos/show/13113 > >> > >> and in the template trace, I verified that @request[''id''] is indeed > >> 13113 (see below), in the logs/development.log file I see this SQL query > >> being run though: > >> > >> SELECT * FROM photos WHERE id = ''--- \"13113\"'' > >> > >> so of course I am getting the error: > >> > >> > >> ActiveRecord::RecordNotFound in Photos#show > >> > >> Couldn''t find Photo with ID = 13113 > >> > >> /app/controllers/photos_controller.rb:16:in `show'' > >> > >> here is my request: > >> > >> Request > >> > >> Parameters: {"site_id"=>"1", "id"=>"13113"} > >> > >> Why in the world is id set to ''-- \"13113\"''? > >> > >> Thanks! > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
What''s even wierder, I ran it against another controller, that basically does the same thing: /items/show/12345 and the value.class for the call to abstract_adaptor.quote was Fixnum, so it worked fine. It just seems to be this one controller Sascha Ebach wrote:>> else "''#{quote_string(value.to_yaml)}''" > > which should be "''#{quote_string(value)}''" i guess. What you get is yaml > output which is prolly not what you want. >
Nm - I was calling find_first in the items controller, I switched it to use find(@request[''id'']) and I got the same error, so it seems global to the find() call when it calls sanitize(id) Sean Leach wrote:> What''s even wierder, I ran it against another controller, that basically > does the same thing: > > /items/show/12345 > > and the value.class for the call to abstract_adaptor.quote was Fixnum, > so it worked fine. It just seems to be this one controller > > Sascha Ebach wrote: >>> else "''#{quote_string(value.to_yaml)}''" >> >> which should be "''#{quote_string(value)}''" i guess. What you get is yaml >> output which is prolly not what you want. >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On Thu, 16 Dec 2004 16:18:05 -0800, Sean Leach <sleach-IaTyVoCi2nzQT0dZR+AlfA@public.gmane.org> wrote:> Nm - I was calling find_first in the items controller, I switched it to > use find(@request[''id'']) and I got the same error, so it seems global to > the find() call when it calls sanitize(id)The ID should really by typecast in the find method. We know the type of the primary key, can''t we convert use ids.collect{|id| convert_to_correct_type(id)}.map .....? This seems like quite the show stopper, I assume DHH is in bed or something?> Sean Leach wrote: > > What''s even wierder, I ran it against another controller, that basically > > does the same thing: > > > > /items/show/12345 > > > > and the value.class for the call to abstract_adaptor.quote was Fixnum, > > so it worked fine. It just seems to be this one controller > > > > Sascha Ebach wrote: > >>> else "''#{quote_string(value.to_yaml)}''" > >> > >> which should be "''#{quote_string(value)}''" i guess. What you get is yaml > >> output which is prolly not what you want. > >> > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
On Fri, 17 Dec 2004 13:42:03 +1300, Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, 16 Dec 2004 16:18:05 -0800, Sean Leach <sleach-IaTyVoCi2nzQT0dZR+AlfA@public.gmane.org> wrote: > > Nm - I was calling find_first in the items controller, I switched it to > > use find(@request[''id'']) and I got the same error, so it seems global to > > the find() call when it calls sanitize(id) > > The ID should really by typecast in the find method. We know the > type of the primary key, can''t we convert use ids.collect{|id| > convert_to_correct_type(id)}.map .....? > > This seems like quite the show stopper, I assume DHH is in bed or something?Hieraki runs on Rails 0.9, and it''s code is filled with find(@params["id"]) @book = Book.find(@params[''id'']) etc.> > Sean Leach wrote: > > > What''s even wierder, I ran it against another controller, that basically > > > does the same thing: > > > > > > /items/show/12345 > > > > > > and the value.class for the call to abstract_adaptor.quote was Fixnum, > > > so it worked fine. It just seems to be this one controller > > > > > > Sascha Ebach wrote: > > >>> else "''#{quote_string(value.to_yaml)}''" > > >> > > >> which should be "''#{quote_string(value)}''" i guess. What you get is yaml > > >> output which is prolly not what you want. > > >> > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Cheers > > Koz >-- Cheers Koz
Michael Koziarski wrote:> Hieraki runs on Rails 0.9, and it''s code is filled with > find(@params["id"]) > > @book = Book.find(@params[''id'']) > > etc. >And that solved it :) I was using @request[''id''] like I was under 0.85. When I switched to @params[''id''], it worked fine.