glacials / friendly_uuid

Short, stateless URL slugs for UUID-based Rails models
Other
48 stars 3 forks source link

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

Closed saxxi closed 2 months ago

saxxi commented 1 year ago

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.

glacials commented 1 year ago

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

ianbayne commented 3 months ago

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