FIX: Ensure category_id is an integer

FIX: Ensure category_id is an integer

diff --git a/app/models/category.rb b/app/models/category.rb
index 8a29f61..5fb020c 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -167,7 +167,7 @@ class Category < ActiveRecord::Base
       SQL
     DB.query_single(
       sql,
-      category_id: category_id,
+      category_id: category_id.to_i,
       max_category_nesting: SiteSetting.max_category_nesting
     )
   end

GitHub sha: f8ec5f30

Probably minor but wouldn’t: Integer(category_id) be more correct? because :

nil.to_i # 0

Integer(nil) # TypeError (can't convert nil into Integer)

Integer("1") # 1

1 Like

I believe a better solution would be to ensure that the caller always passes an integer and avoid the cast altogether. Probably the call which was causing issues is coming from Topic which passed non-nil strings instead of integers.

I will get back to this on Monday with some other changes.

2 Likes

Followed up with