From 4f944366ecd16531dffccffab39bb47e5f5cf34c Mon Sep 17 00:00:00 2001 From: Kevin Bruccoleri Date: Fri, 6 Sep 2024 16:33:08 -0400 Subject: [PATCH] Handle ActiveRecord::Locking::LockingType ActiveRecord::Locking::LockingType is used for the lock_version column to handle Optimistic Locking: https://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html - This type was falling into the else block and causing a Sorbet Error: Expected type ::Object, got type ActiveRecord::Locking::LockingType with value # (SorbetError) The column_type is really just a wrapper for a potentially nilable integer, so we make a specific exception for it. Co-authored-by: Carlos Quinones Co-authored-by: Alexander Momchilov --- lib/tapioca/dsl/helpers/active_record_column_type_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb b/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb index 270757cc5..1d41fb89d 100644 --- a/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +++ b/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb @@ -211,6 +211,11 @@ def type_for_activerecord_value(column_type, column_nullability:) ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range === type } "T::Range[#{type_for_activerecord_value(column_type.subtype, column_nullability:)}]" + when ->(type) { + defined?(ActiveRecord::Locking::LockingType) && + ActiveRecord::Locking::LockingType === type + } + as_non_nilable_if_persisted_and_not_nullable("::Integer", column_nullability:) else as_non_nilable_if_persisted_and_not_nullable( ActiveModelTypeHelper.type_for(column_type),