From 2d5e3c453a3bb845a0968593d70ecd7584005bdc 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 --- .../dsl/helpers/active_record_column_type_helper.rb | 8 ++++++++ 1 file changed, 8 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 7dd8a5999..6e57930eb 100644 --- a/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +++ b/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb @@ -191,6 +191,14 @@ def type_for_activerecord_value(column_type, column_nullability:) ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array === type } "T::Array[#{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: column_nullability, + ) else as_non_nilable_if_persisted_and_not_nullable( ActiveModelTypeHelper.type_for(column_type),