Skip to content

Commit

Permalink
Handle ActiveRecord::Locking::LockingType
Browse files Browse the repository at this point in the history
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 #<ActiveModel::Type::Intege...ange=-2147483648...2147483648> (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 <[email protected]>
Co-authored-by: Alexander Momchilov <[email protected]>
  • Loading branch information
3 people committed Dec 11, 2024
1 parent 261fcd2 commit 4f94436
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tapioca/dsl/helpers/active_record_column_type_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 4f94436

Please sign in to comment.