Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `split' for nil:NilClass #212

Open
brandondrew opened this issue Aug 15, 2023 · 2 comments
Open

undefined method `split' for nil:NilClass #212

brandondrew opened this issue Aug 15, 2023 · 2 comments

Comments

@brandondrew
Copy link

brandondrew commented Aug 15, 2023

I just installed database_consistency and ran it in my project. At first glance it looks like it would be fixed by using &.split(',')&.map(&:strip) but I may be mistaken since I didn't actually test that.

<===begin===>
Metadata:
model: Enrollment
column: status
checker: DatabaseConsistency::Checkers::EnumValueChecker
Stack trace:
/Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/checkers/column_checkers/enum_value_checker.rb:40:in `enum_column_values': �[1mundefined method `split' for nil:NilClass (�[1;4mNoMethodError�[m�[1m)�[m

�[1m          values.split(',').map(&:strip)�[m
�[1m                ^^^^^^�[m
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/checkers/column_checkers/enum_value_checker.rb:47:in `verify_enum'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/checkers/column_checkers/enum_value_checker.rb:32:in `check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/checkers/base_checker.rb:25:in `report'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/checkers/base_checker.rb:34:in `report_if_enabled?'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:29:in `block (6 levels) in check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/debug_context.rb:20:in `with'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/debug_context.rb:8:in `with'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:27:in `block (5 levels) in check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:26:in `each'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:26:in `flat_map'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:26:in `block (4 levels) in check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/debug_context.rb:20:in `with'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/debug_context.rb:8:in `with'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:25:in `block (3 levels) in check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:24:in `each'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:24:in `flat_map'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:24:in `block (2 levels) in check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/debug_context.rb:20:in `with'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/debug_context.rb:8:in `with'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:20:in `block in check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:19:in `each'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:19:in `flat_map'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/columns_processor.rb:19:in `check'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/base_processor.rb:31:in `reports'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/base_processor.rb:16:in `block in reports'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/base_processor.rb:15:in `each'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/base_processor.rb:15:in `flat_map'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency/processors/base_processor.rb:15:in `reports'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/lib/database_consistency.rb:112:in `run'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/database_consistency-1.7.18/bin/database_consistency:78:in `<top (required)>'
	from /Users/brandon/.rbenv/versions/3.2.2/bin/database_consistency:25:in `load'
	from /Users/brandon/.rbenv/versions/3.2.2/bin/database_consistency:25:in `<top (required)>'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/cli.rb:492:in `exec'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/cli.rb:34:in `dispatch'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/cli.rb:28:in `start'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/exe/bundle:37:in `block in <top (required)>'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/brandon/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.15/exe/bundle:29:in `<top (required)>'
	from /Users/brandon/.rbenv/versions/3.2.2/bin/bundle:25:in `load'
	from /Users/brandon/.rbenv/versions/3.2.2/bin/bundle:25:in `<main>'
<===end===>
@djezzzl
Copy link
Owner

djezzzl commented Aug 22, 2023

Hi @brandondrew,

Thank you for reporting this! I will have a look this weekend, maybe, early.

@neanias
Copy link

neanias commented Feb 20, 2024

Hi there,

I've seen this issue too and I suspect it might be to do with the activerecord-postgres_enum gem. We're using it (currently) in our Rails app. (Aside: it could be considered redundant with Rails 7.1+ as all its functionality is now in core.)

This gem overrides enum_types to return a symbol-keyed hash rather than a key-pair array:

# With vanilla Rails 7.1
model.connection.enum_types == [["field_type", "value1,value2"], ["status_type", "value1,value2"]]

# With `activerecord-postgres_enum`
model.connection.enum_types == { field_type: ["value1", "value2"], status_type: ["value1", "value2"] }

This checker could be changed to handle both styles, but it seems outwith what this gem is actually aiming to support.

In terms of fixing this issue, I'd think values should default to an empty array if it can't handle the contents of the enum_types return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants