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

Fix NoMethodError preparable for Arel::Visitors::PostgreSQL #22748

Merged
merged 1 commit into from
Feb 22, 2016

Conversation

kelhusseiny
Copy link
Contributor

After upgrading to 5.0.0.beta1 I got an error called

  `select_all': undefined method `preparable' for #<Arel::Visitors::PostgreSQL:0x007ff9416cf718> (NoMethodError)

So I did debug the problem and I found that module DetermineIfPreparableVisitor is extended only in case database configs for prepared_statements is true.

  @visitor = Arel::Visitors::PostgreSQL.new self
  if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
    @prepared_statements = true
    @visitor.extend(DetermineIfPreparableVisitor)
  else
    @prepared_statements = false
  end

for that, I did that to fix the problem, and it works fine now 👍

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@kelhusseiny kelhusseiny changed the title Fix NoMethodError preparable for Arel::Visitors Fix NoMethodError preparable for Arel::Visitors::PostgreSQ Dec 22, 2015
@kelhusseiny kelhusseiny changed the title Fix NoMethodError preparable for Arel::Visitors::PostgreSQ Fix NoMethodError preparable for Arel::Visitors::PostgreSQL Dec 22, 2015
@matthewd
Copy link
Member

Thanks! Can you add a test?

@kelhusseiny
Copy link
Contributor Author

@matthewd After searching I found the only related file that tests DatabaseStatements here which doesn't include any tests for prepared_statements config. Do you think that I should add new tests for that case here?

@adityashedge
Copy link

Just wanted to say that this is a genuine issue with Postgresql which you can reproduce by setting prepared_statements: false in your database.yml.

Tested with gem 'rails', '>= 5.0.0.beta1', '< 5.1'

@kelhusseiny
Copy link
Contributor Author

@adityashedge Yeah That's right. But our system has much complex queries which don't work with prepared_statements: true. For that we can't upgrade to rails5.
@matthewd Just a gentle reminder. What are we going to do with this please to get it merged?

@dhh dhh assigned matthewd and unassigned schneems Feb 10, 2016
@sgrif
Copy link
Contributor

sgrif commented Feb 11, 2016

@Azzurrio Nothing has changed on this since his original comment. This needs a test.

@sgrif sgrif assigned sgrif and unassigned matthewd Feb 11, 2016
@matthewd
Copy link
Member

@Azzurrio I imagine pretty much any test that does a query will work to exercise this. Personally, I'd look for other tests that temporarily vary the connection configuration.

@kelhusseiny
Copy link
Contributor Author

@matthewd & @sgrif Ok, I've added a test. Does it able to merge now?

@kelhusseiny
Copy link
Contributor Author

@sgrif Just a reminder, Is this missing something else?

@sferik
Copy link
Contributor

sferik commented Feb 19, 2016

👍

fixtures :developers

def setup
Developer.connection_config[:prepared_statements] = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pollutes the config for subsequent tests; we need a teardown that puts it back how it was

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewd done! 👍

@kelhusseiny
Copy link
Contributor Author

@matthewd Are we done with this?

@matthewd
Copy link
Member

Sorry... is it really true before this test runs? I would've thought it would be unset.

@kelhusseiny
Copy link
Contributor Author

@matthewd yeah it was unset which defaults to true. Do you suggest to use Developer.connection_config.delete(:prepared_statements) instead?

@matthewd
Copy link
Member

We should probably just store the existing value in a variable then put it back afterwards, so this test doesn't have any knowledge of what the default is. (Technically we'd be changing it from not-present to explicitly-nil, but I think it's safe to pretend those are the same.)

@kelhusseiny
Copy link
Contributor Author

@matthewd Okay done 👍

matthewd added a commit that referenced this pull request Feb 22, 2016
Fix NoMethodError preparable for Arel::Visitors::PostgreSQL
@matthewd matthewd merged commit c901fad into rails:master Feb 22, 2016
@matthewd
Copy link
Member

Thanks ❤️

prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this pull request Nov 20, 2016
- Due to `assert_nothing_raised` this test was not really testing
  anything.
- So updated it to assert that the query gives expected result.
- Also in general we can use `connection.unprepared_statement` for
  testing queries w/o prepared statements but it can't be used in this
  case. This test cases was added because when prepared_statements
  config is set to false, then DetermineIfPreparableVisitor module
  does not extended by Arel visitor resulting into an error. Ref: rails#22748.
- Because DetermineIfPreparableVisitor module does not get added to the
  visitor chain only if prepared_statements is false while **setting up
  connection**, not when `unprepared_statement` is used.
- I have also added an assertion for making sure that prepared_config
  is set to false from the start, so that nobody accidentally removes
  the connection setup using `arunit_without_prepared_statements` and
  replaces it with stubs or unprepared_statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants