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

Missing value while forming the SQL prepared statement #50

Open
jsantos opened this issue Aug 22, 2019 · 3 comments
Open

Missing value while forming the SQL prepared statement #50

jsantos opened this issue Aug 22, 2019 · 3 comments

Comments

@jsantos
Copy link

jsantos commented Aug 22, 2019

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.

@robinbortlik
Copy link
Owner

robinbortlik commented Aug 22, 2019

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?

@jsantos
Copy link
Author

jsantos commented Aug 23, 2019

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.

@robinbortlik
Copy link
Owner

Ok, let me know if you find something.

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

No branches or pull requests

2 participants