Shopify / tapioca

The swiss army knife of RBI generation
MIT License
701 stars 115 forks source link

`tapioca dsl` fails on Rails 6.1 models due to ActiveRecord::Encryption reference #1913

Closed aalong-tr closed 1 month ago

aalong-tr commented 1 month ago

Repo with simple reproduction here: https://github.com/aalong-tr/tapioca-rails-6-encryption

Tapioca version 0.14.3 includes improvements from #1904 to better handle Rails 7 encrypted attribute behaviors. Unfortunately this logic references a constant that does not exist on Rails 6. As a result, the tapioca dsl command run against a Rails 6.1 application produces the error:

bundler: failed to load command: tapioca (/Users/drew/.rbenv/versions/3.1.4/bin/tapioca)
/Users/drew/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/tapioca-0.14.3/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb:72:in `type_for_activerecord_value': NameError: uninitialized constant ActiveRecord::Encryption (Parallel::UndumpableException)

          when ActiveRecord::Encryption::EncryptedAttributeType
                           ^^^^^^^^^^^^
Did you mean?  Exception
KaanOzkan commented 1 month ago

Thanks for the issue. I believe Rails 6.1 will be EOL soon so I'm not sure if we should support this out of the box. In the meantime feel free to override the method and remove the reference in your application.

swiknaba commented 1 month ago

For now, placing this in e.g. your config/application.rb file fixes the issue:

# https://github.com/Shopify/tapioca/issues/1913
module ActiveRecord
  module Encryption
    class EncryptedAttributeType; end # rubocop:disable Lint/EmptyClass
  end
end

Dropping support for a Rails version (that is not EOL since a long time) might be worth a major version jump?

paracycle commented 1 month ago

@swiknaba Rails 6.1 has been EOL since Rails 7.1 was released in October 2023 based on the maintenance policy of Rails:

The current release series and the next most recent one will receive patches and new versions in case of a security issue.

The core team has chosen to continue doing security releases for 6.1 series, as an exception, but that doesn't mean it is a supported version.

Tapioca follows the Rails and Ruby support schedules very closely, we drop official support for any versions that are no longer supported.

We enforce minimum versions of Ruby using the required_ruby_version in the gemspec, and we could do something similar to the versions of Rails that we support (via a runtime check, though) and refuse to generate any Rails related DSL RBIs if the version doesn't match.

We have opted to not do that, and to allow folks on older Ruby versions to be able to use Tapioca, but we won't be testing against older versions and, thus, support for them is best effort.