I'm trying to make our application more resilient to downtime from our search server. To achieve this, I'm trying to disable the automatic indexing and removal, and manual perform them in a background process.
I'm trying
searchable :auto_index => false, :auto_remove => false do
...
end
But am still receiving a connection error, every time I try to save or destroy the record.
The backtrace shows that the error is coming from the solr searchable file, so it's definetly sunspot_rails causing the problem. Here is a slice from the backtrace on destroy:
...
rsolr (1.0.8) lib/rsolr/client.rb:67:in `update'
rsolr (1.0.8) lib/rsolr/client.rb:121:in `delete_by_id'
sunspot (1.3.3) lib/sunspot/indexer.rb:36:in `remove'
sunspot (1.3.3) lib/sunspot/session.rb:137:in `block in remove'
sunspot (1.3.3) lib/sunspot/session.rb:136:in `each'
sunspot (1.3.3) lib/sunspot/session.rb:136:in `remove'
sunspot (1.3.3) lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `remove'
sunspot (1.3.3) lib/sunspot.rb:410:in `remove'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:390:in `solr_remove_from_index'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:93:in `block in searchable'
...
Any idea why the options to disable these hooks aren't working? Any idea how to actually disable them?
Thanks
Found the answer to my own question:
Turns out that while automatic callbacks were disabled, I was still making it dirty in a different step. sunspot_rails has a cleanup step that runs at the end of a request and tries to commit all dirty records to the solr server. To disable it add auto_commit_after_request: false to your sunspot.yml.
Related
this is what I believe a simple problem I need help with. I'm trying to modify a gem's method so that I can add another argument to it. For this, I've cloned the gem's repo to a local directory and changed the code I needed. Inside my app's Gemfile I'm doing this:
gem 'recommendable', path: "/home/aristizabal95/forked_gems/recommendable"
And running bundle install afterwards. Even though the bundler says it's using my code, when I run the tests I get this error:
ArgumentError: wrong number of arguments (given 4, expected 1..3)
from /var/lib/gems/2.3.0/gems/recommendable-2.2.0/lib/recommendable/rater/recommender.rb:21:in `recommended_for'
which indicates that the app is not running my version of the gem, but the original one. I have no idea why it's not working, and was unable to find any issue related to this.
Thanks in advance
EDIT:
This is what the Gemfile.lock looks like
PATH
remote: /home/aristizabal95/forked_gems/recommendable
specs:
recommendable (2.2.1)
activesupport (>= 3.0.0)
hooks (>= 0.2.1)
redis (>= 2.2.0)
GEM
recommendable!
My guess is that spring still has the gem from the original gem source loaded.
To force spring to reload the gem (from your local source), do:
spring stop
in the console. Then restart your server and you should be using the gem from your local source.
I'm getting a heroku api error since 26th of June 2017 for a missing heroku api.
The error is as follows:
(1.9ms) COMMIT
(1.9ms) COMMIT
(8.0ms) SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL
(8.0ms) SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL
Heroku::API::Errors::ErrorWithResponse: Expected(200) <=> Actual(410 Gone)
body: "{\"id\":\"gone\",\"error\":\"This version of the API has been Sunset.\\nPlease see https://devcenter.heroku.com/changelog-items/1147 for more information.\\n\"}"
from /app/vendor/bundle/ruby/2.2.0/gems/excon-0.57.0/lib/excon/middlewares/expects.rb:7:in `response_call'
The error is pretty explainitory and I've had a look at the url https://devcenter.heroku.com/changelog-items/1147 which shows the api that has been removed, but after updating everything I'm still getting the error. I'm not directly using the API and I think I've narrowed it down to the deleyed_job gem, as I can run in the heroku console
Product.some_function()
and it works fine, but then if I run:
Product.delay.some_function()
I get the error pasted above. I'm using the delayed job and the workless gems in my gemfile and both have been updated with no change.
Here is a snippet from my Gemfile.lock
.
.
.
delayed_job (4.1.3)
activesupport (>= 3.0, < 5.2)
delayed_job_active_record (4.1.2)
activerecord (>= 3.0, < 5.2)
delayed_job (>= 3.0, < 5)
.
.
.
heroku-api (0.4.2)
.
.
.
workless (1.2.3)
delayed_job (>= 2.0.7)
heroku-api
rails
rush
.
.
.
DEPENDENCIES
.
.
.
delayed_job_active_record
.
.
.
Does anyone know which part of the API the delayed_job gem is using that is causing the errors? And am I going to have to go in and monkey patch the gem in order to get it to work, or is there something else wrong that I am missing. Any help is GREATLY appreciated! I've been banging my head against the wall for this one as there isn't anything that seems to have an effect!
Thanks!
So it was the 'workless' gem after all. For anyone else who find this just replace the workless gem with this by davidakachaos:
https://github.com/davidakachaos/workless_revived
There is a little bit of fiddling to get it working as it's not exactly the same. Just make sure you are on his latest release of the gem (2.1) and follow his setup instructions.
Thank you davidakachaos for your work(less)!
I have some Ruby on Rails / ActiveRecord code that is giving me the following Postgres error:
PG::SyntaxError: ERROR: non-integer constant in ORDER
I'm not sure why since it is a simple fetch ordered by created_at
self.posts.order(created_at: :desc).limit(25)
What do I do to change this?
I am not sure that syntax is supported in older versions of Rails, which is where I suspect you are. Try this instead:
self.posts.order("created_at desc").limit(25)
I have experienced this error as well after switching my Rails app from MySQL to PostgreSQL (my development environment and Gem list are at the bottom of this post).
The error appears to be caused by PostgreSQL expecting the column names in a SQL query to be double-quoted, as I am able to eliminate the error by changing my ".order()" parameter from hash-format to a literal string:
This Rails code triggers the error:
ModelName.where(:attribute => self.id).order(col1: :desc, col2: :asc)
...and the resulting error:
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
ModelName Load (1.0ms) SELECT "model_name".* FROM "model_name" WHERE ("model_name"."attribute" = 14) ORDER BY '{:col1=>:desc, :col2=>:asc}'
PG::SyntaxError: ERROR: non-integer constant in ORDER BY
LINE 1: ...E ("model_name"."attribute" = 14) ORDER BY '{:col1=...
^
Whereas this Rails code works without triggering the error message:
ModelName.where(:attribute => self.id).order("\"col1\" desc, \"col2\" asc")
I know that PostgreSQL is able to correctly interpret non-quoted identifiers, but the format of the query that ActiveRecord generates in this case appears to be ambiguous to Postgresql. Here's a description of PostgreSQL query syntax: http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html
Here's my development environment:
Windows 7
Ruby 2.1.5p273
Rails 3.0.3 (I know it's old...)
PostgreSQL 9.4 (on windows)
...and here's the pertinent part of my gem list:
*** LOCAL GEMS ***
abstract (1.0.0)
afm (0.2.2)
arel (2.0.10)
builder (2.1.2)
bundler (1.7.7)
hashery (2.1.1)
i18n (0.6.11)
mysql (2.9.1)
pg (0.18.1 x86-mingw32)
rack (1.2.8)
rails (3.0.3)
railties (3.0.3)
rake (0.9.2.2)
ruby-rc4 (0.1.5)
sequel (3.31.0)
valkyrie (0.0.2)
I have been scouring the Internet for an answer to this but I'm out of ideas. I am using Devise with Rails 3 to authenticate with LDAP. I'm using Rails 3 with Ruby 1.9.2. I'm using mysql2 as the database connector.
I can get this to work with the rails console so I know my addresses and everything are correct.
We have an active directory and in order to authenticate we have to prefix the login name with systems. So my login would be systems\crudbasher.
This works in the console but when I have a form with login name and password I get this error.
Encoding::CompatibilityError in Devise::SessionsController#create
incompatible character encodings: ASCII-8BIT and UTF-8
Ok I get that it is having a problem with the backslash. What I don't understand is how to fix it.
The full stack trace if it helps is this:
net-ldap (0.2.2) lib/net/ber/core_ext/array.rb:62:in `to_ber_seq_internal'
net-ldap (0.2.2) lib/net/ber/core_ext/array.rb:54:in `to_ber_contextspecific'
net-ldap (0.2.2) lib/net/ldap/filter.rb:509:in `to_ber'
net-ldap (0.2.2) lib/net/ldap.rb:1380:in `block in search'
net-ldap (0.2.2) lib/net/ldap.rb:1361:in `loop'
net-ldap (0.2.2) lib/net/ldap.rb:1361:in `search'
net-ldap (0.2.2) lib/net/ldap.rb:635:in `search'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:208:in `search_for_login'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:86:in `dn'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:124:in `authorized?'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:14:in `valid_credentials?'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/model.rb:39:in `valid_ldap_authentication?'
activesupport (3.1.1) lib/active_support/core_ext/object/try.rb:32:in `try'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/model.rb:85:in `authenticate_with_ldap'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/strategy.rb:12:in `authenticate!'
I'm really stumped. Thank you to anyone who can help!!
Encoding is always a mess. Have you tried toying around with encode and force_encoding?
I had this same problem and I fixed by updating net-ldap library to 0.3.1, but that broke mine get_ldap_email (which is just like devise_ldap_authenticatable main page example, Querying LDAP)
Also everything seemed to be ok but I'm not 100% sure if nothing else is broken.
Edit: Apparently I also need to update devise_ldap_authenticatable to version 0.4.7 or higher -> Ruby on Rails 3: Devise::LdapAdapter.get_ldap_param undefined method error
But I'm not sure how to update both, devise_ldap and net-ldap, and not breaking my bundle update
I'm trying to run Heckle, and I keep getting an error:
> spec spec/controllers/my_controller_spec.rb --heckle MyController
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! exception= has a thick skin. There's nothing to heckle.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(Runs through several mutations...)
/home/developer/.gem/ruby/1.8/gems/heckle-1.4.3/lib/heckle.rb:603:in `current_code': undefined method `translate' for Ruby2Ruby:Class (NoMethodError)
Any thoughts?
EDIT: I forgot the gem versions:
heckle (1.4.3)
ruby2ruby (1.2.3)
rails (2.3.2, 2.2.2)
rspec (1.2.6)
rspec-rails(1.2.6, 1.1.12)
Install ruby2ruby 1.2.2. There seems to be an API change in 1.2.3.
Just generated the docs for 1.2.2 and 1.2.3
Looks like the class method 'translate' has been totally removed, although the docs don't reflect this