validates_overlap
validates_overlap copied to clipboard
Missing value while forming the SQL prepared statement
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.
Hi @jsantos ,
I haven't been maintaining this gem for a while. So not sure, what changed in the Rails world from that time. But may I ask you, what version of rails are you using? Can you please push somewhere some example application where I can see and test the exception?
I'm currently using Rails 5.2.3. I'll keep investigating this and will let you know if I can isolate the reason why this is happening. This is not happening all the time, so there might be some other factor involved.
Ok, let me know if you find something.