Skip to content

Fix column type discovery running too early - #55

Closed
RDIL wants to merge 3 commits into
Genius:masterfrom
RDIL:reece/column-discovery-error-fix
Closed

Fix column type discovery running too early#55
RDIL wants to merge 3 commits into
Genius:masterfrom
RDIL:reece/column-discovery-error-fix

Conversation

@RDIL

@RDIL RDIL commented Aug 23, 2025

Copy link
Copy Markdown
Member

In a test environment, or when creating/seeding the database, there are no tables defined in ActiveRecord. This causes an edge case, where, if any method_missing is called (and it gets to MSL), an error will be thrown. This is because accessing columns_hash or column_names will cause a query to be made that will fail on the Postgres side (as it expects the table to already be present in the database).

For getting caught up on the memes, see the following:

Additionally, I've fixed another case where column type discovery should not run: abstract classes. This is a common pattern in newer rails apps.

# Column type discovery should NOT be done here
class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  def some_utility_method
    # ...
  end
end

# Column type discovery SHOULD be done here
class User < ApplicationRecord
end

Feel free to backport this to Rails 2 - seems pointless since it's On The Way Out (TM) (as it has been for the last decade, but who's counting?!)

Test Plan

Test suite passes on my local branch.
I haven't PR'd in all this work yet, but it allows the tests to run on Ruby 3.

In a test environment, or when creating/seeding the database, there are no tables defined in ActiveRecord. This causes an edge case where, if *any* `method_missing` is called (and it gets to MSL), an error will be thrown. This is because accessing `columns_hash` or `column_names` will cause a query to be made that will fail (as it expects the table to already be present in the database).

For getting caught up on the memes, see the following:
- Genius/Rap-Genius#15200
- Genius/heroku-buildpack-ruby#14

Feel free to backport this to Rails 2 - seems pointless since it's On The Way Out (TM) (as it has been for the last decade, but who's counting?!)
@RDIL RDIL changed the title Fix column discovery running too early Fix column type discovery running too early Aug 23, 2025
RDIL added 2 commits August 25, 2025 10:13
Same memes, different day. It's not a real model, so it shouldn't crash on column type discovery, since it has no columns.
@RDIL RDIL mentioned this pull request Aug 26, 2025
@RDIL RDIL closed this Sep 23, 2025
@RDIL
RDIL deleted the reece/column-discovery-error-fix branch September 23, 2025 17:20
@RDIL

RDIL commented Sep 23, 2025

Copy link
Copy Markdown
Member Author

Closing due to fork: https://github.com/RDIL/modern_searchlogic (it's published to RubyGems now)

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.

1 participant