friendly_uuid icon indicating copy to clipboard operation
friendly_uuid copied to clipboard

MyModel.find(nil) does not raise ActiveRecord::RecordNotFound

Open saxxi opened this issue 1 year ago • 1 comments

TLDR: MyModel.find(nil) should throw ActiveRecord::RecordNotFound.


What happened:

While doing ClientProject.find(params[:id]) the system 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.

saxxi avatar Aug 02 '23 22:08 saxxi

Nice find and diagnosis! Not much in the way of time recently but Will happily accept a PR.

glacials avatar Aug 03 '23 21:08 glacials

Hi @glacials and @saxxi: I'll take a stab at this if you don't mind. Please go ahead and assign me.

ianbayne avatar Sep 07 '24 03:09 ianbayne