Closed saxxi closed 2 months ago
TLDR: MyModel.find(nil) should throw ActiveRecord::RecordNotFound.
MyModel.find(nil)
ActiveRecord::RecordNotFound
What happened:
While doing ClientProject.find(params[:id]) the system returned with a random record.
ClientProject.find(params[:id])
returned with a random record
Baffled by the result I realised it was simply not throwing an error as internally was instead doing this:
SELECT "client_projects".* FROM "client_projects" WHERE (LEFT(client_projects.id::text, 0) = '') ORDER BY "client_projects"."created_at" ASC LIMIT $1 [["LIMIT", 1]] SELECT "client_projects".* FROM "client_projects" WHERE "client_projects"."id" = $1 LIMIT $2 [["id", "ae7aef7a-..."], ["LIMIT", 1]]
Which lead to realise I had params[:id] == nil.
params[:id] == nil
Nice find and diagnosis! Not much in the way of time recently but Will happily accept a PR.
Hi @glacials and @saxxi: I'll take a stab at this if you don't mind. Please go ahead and assign me.
TLDR:
MyModel.find(nil)
should throwActiveRecord::RecordNotFound
.What happened:
While doing
ClientProject.find(params[:id])
the systemreturned with a random record
.Baffled by the result I realised it was simply not throwing an error as internally was instead doing this:
Which lead to realise I had
params[:id] == nil
.