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 Sep 12, 2024
1 parent 316688e commit 2d5e3c4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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 @@ -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),
Expand Down

0 comments on commit 2d5e3c4

Please sign in to comment.