Skip to content

Missing value while forming the SQL prepared statement #50

@jsantos

Description

@jsantos

I'm seeing an error that is intriguing me, doesn't seem to happen all the time.

I have my overlap conditions defined as:

  scope :active, (-> { where(deleted: false, available: true) })

  validates :starttime, :endtime, overlap: {
    query_options: { active: nil },
    scope: :user_id,
    exclude_edges: ["starttime", "endtime"],
    load_overlapped: true,
    message_title: 'overlap',
    message_content: 'overlaps with another stop',
  }

And I've been getting the following error recently:

ActiveRecord::PreparedStatementInvalid: missing value for :user_id_value in (stops.endtime IS NULL OR stops.endtime > :starts_at_value) AND (stops.starttime IS NULL OR stops.starttime < :ends_at_value) AND stops.user_id  = :user_id_value
  from active_record/sanitization.rb:198:in `block in replace_named_bind_variables'
  from active_record/sanitization.rb:192:in `gsub'
  from active_record/sanitization.rb:192:in `replace_named_bind_variables'
  from active_record/sanitization.rb:126:in `sanitize_sql_array'
  from active_record/sanitization.rb:26:in `sanitize_sql_for_conditions'
  from active_record/relation/where_clause_factory.rb:14:in `build'
  from active_record/relation/query_methods.rb:591:in `where!'
  from active_record/relation/finder_methods.rb:370:in `construct_relation_for_exists'
  from active_record/relation/finder_methods.rb:320:in `exists?'
  from validates_overlap/overlap_validator.rb:52:in `overlapped_exists?'
  from validates_overlap/overlap_validator.rb:21:in `validate'
  ...

I've verified and user_id used on the :scope is never nil (no records like that, and validations protect against that. Also looked into the conditions on overlap_validator and don't see anything wrong. The save statement triggering this runs inside a transaction.

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