Skip to content

missing_presence_validation crashes with NoMethodError: undefined method 'exclude?' for Symbol #238

Description

@andy-rootly

Note: This issue was written with AI assistance.

Description

missing_presence_validation crashes when a model uses an inclusion or exclusion validator where :in is a Symbol (i.e., a method name):

validates :status, inclusion: { in: :allowed_statuses }

The detector calls .exclude? on the Symbol value, which fails because Symbol does not respond to exclude?.

Error

NoMethodError: undefined method 'exclude?' for an instance of Symbol

                  (validator_items.is_a?(Proc) || validator_items.exclude?(nil))
                                                                 ^^^^^^^^^

Root cause

In lib/active_record_doctor/detectors/missing_presence_validation.rb, inclusion_or_exclusion_validator_items returns validator.options[:in], which can be a Symbol when the validator delegates to a method. The calling code on lines 96 and 103 assumes the result responds to .exclude? / .include?, which Symbols do not.

Environment

  • active_record_doctor 2.0.1
  • Rails 8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions