Skip to content

Comments

Prevent attr_encrypted from making queries on load#468

Merged
joshbranham merged 1 commit intoattr-encrypted:masterfrom
boimw:master
May 22, 2025
Merged

Prevent attr_encrypted from making queries on load#468
joshbranham merged 1 commit intoattr-encrypted:masterfrom
boimw:master

Conversation

@boimw
Copy link
Contributor

@boimw boimw commented May 21, 2025

#attribute_instance_methods_as_symbols can trigger a query when the schema cache is not loaded.

We only need the results of this method if
attribute_instance_methods_as_symbols_available? is true so we move this inside the check.

`#attribute_instance_methods_as_symbols` can trigger a query when the
schema cache is not loaded.

We only need the results of this method if
`attribute_instance_methods_as_symbols_available?` is true so we move
this inside the check.

Signed-off-by: Bojan Marjanovic <marjanovic93@gmail.com>
@boimw
Copy link
Contributor Author

boimw commented May 21, 2025

Hey @joshbranham 👋

could you please review/merge this tiny fix? 🙇‍♂️

@joshbranham joshbranham merged commit 6d8928b into attr-encrypted:master May 22, 2025
26 checks passed
TC-SJ-Yoon added a commit to Zetatango/attr_encrypted that referenced this pull request Feb 23, 2026
* Add (failable) tests to Travis for RoR 6/6.1/7

* Restrict set_attribute_was patch to Rails versions >= 5.2, < 6

Signed-off-by: Josh Branham <josh.php@gmail.com>

* Don't use Gem requirement comparison with frozen Gem::Version

* Disallow failures for RoR 6.0+ tests on travis

As those should be passing or otherwise dealt with by the
time this is merged

* Use #write_cast_value to register the original value before change for Rails >= 5.2

Use #write_cast_value instead of #set_attribute_was patch

* Prefix 'attr_encrypted' to encrypted_attributes method to avoid clash with Rails 7

Prefix 'attr_encrypted' to encrypt and decrypt methods to avoid clash with Rails 7

Adopted from PR: attr-encrypted#425

* Hardcoding sqlite3 gem version to 1.5.4 since newer sqlite3 versions removed native gem support for Ruby 2.6

* Release 4.0.0

* Drop gem signing (attr-encrypted#436)

* Drop support for DataMapper (attr-encrypted#439)

This project has been dead since 2018

* Update README.md (attr-encrypted#441)

* Start testing ruby 3 (attr-encrypted#440)

* Start testing ruby 3

* Exclude older AR and newer Ruby combos

* Add Ruby 3.0.6 as well

* Exclude 3.0.6 and AR 5.x

* Use ActiveRecord.deprecator when available (attr-encrypted#437)

Rails 7.1 will deprecate using the singleton ActiveSupport::Deprecation
instance. This directly uses the one from ActiveRecord.

Co-authored-by: Josh Branham <josh.php@gmail.com>

* Use Github Actions for CI (attr-encrypted#442)

* Use Github Actions for CI

* Add back old Rails versions

* Only test Rails 5 on Ruby 2.7

---------

Co-authored-by: Josh Branham <josh.php@gmail.com>

* Fix minitest guard for rails 4 breaking specs (attr-encrypted#448)

Co-authored-by: Josh Branham <joshbranham@sophie-mba.local>

* Add Josh and Mike to authors (attr-encrypted#447)

* Add Josh and Mike to authors

Signed-off-by: Josh Branham <josh.php@gmail.com>

* Update attr_encrypted.gemspec

Signed-off-by: Josh Branham <josh.php@gmail.com>

---------

Signed-off-by: Josh Branham <josh.php@gmail.com>

* Add GitHub Actions badge to README (attr-encrypted#449)

* Update README.md

Signed-off-by: Josh Branham <josh.php@gmail.com>

* Update README.md

Signed-off-by: Josh Branham <josh.php@gmail.com>

---------

Signed-off-by: Josh Branham <josh.php@gmail.com>

* Deprecate testing with travis (attr-encrypted#450)

* Add rails7.1 and Ruby3.3 to CI matrix (attr-encrypted#453)

* Release v4.1.0 (attr-encrypted#455)

* Fix SystemStackError when extending the reload method with Module#prepend (attr-encrypted#457)

For example, when using the master branch of activerecord-multi-tenant, if activerecord-multi-tenant and attr_encrypted are listed in the Gemfile in that order, calling the reload method raises a SystemStackError. This happens because activerecord-multi-tenant extends Active Record’s reload method using prepend, while attr_encrypted extends it using an alias method.

Here’s an example of how extending the same method with both prepend and alias methods in that order can result in a SystemStackError

```
class Hello
  def hello
    'hello'
  end
end

Hello.prepend(Module.new do
  def hello
    super
  end
end)

Hello.class_eval do
  alias orig_hello hello

  def hello
    "#{orig_hello} world"
  end
end

Hello.new.hello #=> SystemStackError
```

However, reversing the order works:

```
class Hello
  def hello
    'hello'
  end
end

Hello.class_eval do
  alias orig_hello hello

  def hello
    "#{orig_hello} world"
  end
end

Hello.prepend(Module.new do
  def hello
    super
  end
end)

Hello.new.hello #=> "hello world"
```

This issue can be resolved by standardizing the method extension to use prepend to avoid conflicts.

* Release 4.1.1 (attr-encrypted#458)

* Add Rails7.2, 8.0 and Ruby 3.4 to CI matrix

Also updated actions/checkout to the latest v4.

* Fix CI failures for Rails 6.0 to 7.0.

The CI failures for Rails 6.0 to 7.0 are caused by changes introduced in concurrent-ruby v1.3.5.

ref: [Rails 7.0.8 fails to create an app with most recent concurrent-ruby version · Issue #54260 · rails/rails](rails/rails#54260)

Update concurrent-ruby to a version below 1.3.5 to fix the tests.

* Set the sqlite3 version to 2.1.0 or higher for Rails 8.0.

To run CI with Rails 8.0, sqlite3 version 2.1.0 or higher is required.

* Remove the unused dm-sqlite-adapter

dm-sqlite-adapter is a SQLite adapter for DataMapper.

https://github.com/datamapper/dm-sqlite-adapter

Since support for DataMapper was dropped in version 4.1.0, this gem is no longer needed as a dependency.

* Set required_ruby_version >= 2.7.0 (attr-encrypted#464)

* Release 4.2.0

* Release 4.2.0 (attr-encrypted#465)

* Prevent attr_encrypted from making queries on load (attr-encrypted#468)

`#attribute_instance_methods_as_symbols` can trigger a query when the
schema cache is not loaded.

We only need the results of this method if
`attribute_instance_methods_as_symbols_available?` is true so we move
this inside the check.

Signed-off-by: Bojan Marjanovic <marjanovic93@gmail.com>

* Reduce gem size by excluding test files (attr-encrypted#470)

Co-authored-by: Yuri Zubov <yuri.zubov@cleverlabs.io>

---------

Signed-off-by: Josh Branham <josh.php@gmail.com>
Signed-off-by: Bojan Marjanovic <marjanovic93@gmail.com>
Co-authored-by: Mike Vastola <mike@vasto.la>
Co-authored-by: Josh Branham <josh.php@gmail.com>
Co-authored-by: Josh Branham <jbranham@salsify.com>
Co-authored-by: Vimal V Nair <vimalvnair999@gmail.com>
Co-authored-by: Matt Larraz <mlarraz@users.noreply.github.com>
Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
Co-authored-by: Josh Branham <joshbranham@sophie-mba.local>
Co-authored-by: Shinichi Maeshima <netwillnet@gmail.com>
Co-authored-by: Josh Branham <jbranham@redhat.com>
Co-authored-by: Bojan Marjanovic <marjanovic93@gmail.com>
Co-authored-by: Yuri Zubov <yury.zubau@gmail.com>
Co-authored-by: Yuri Zubov <yuri.zubov@cleverlabs.io>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants