Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 2.2: PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8"

I am upgrading Rails 4.1 app to use Ruby 2.2. During upgrade it turned out that the app used old version of pg gem (0.12) and gem was not installing using Ruby 2.2. So I tried to use newer version of pg gem (0.17.1). Now I sometimes get following error when a new user is created in the system:

PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8"

Are there any known issues with Ruby 2.2 and Postgres?

Looks like application is configured to use unicode: config.encoding = "utf-8" is set in application.rb and encoding: unicode is in database.yml

SQL statement:

INSERT INTO "users" (
  "confirmation_sent_at", 
  "confirmation_token", 
  "created_at", 
  "email", 
  "encrypted_password", 
  "first_name", 
  "last_name", 
  "updated_at") 
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8) 
  RETURNING "id"
like image 746
Andrew Bezzub Avatar asked Dec 29 '14 04:12

Andrew Bezzub


2 Answers

Looks like this is a known issue with "pg" gem: https://bitbucket.org/ged/ruby-pg/issue/197/ruby-220-byte-encoding-issue

It should be fixed in 0.18 pre-release

like image 132
Andrew Bezzub Avatar answered Sep 28 '22 08:09

Andrew Bezzub


There is definitely some kind of bug in Ruby 2.2.0 re UTF-8 encoding with Postgres. I upgraded a previously bug free Rails 4.1.5 app from Ruby 2.1.5 to Ruby 2.2.0 and started getting these errors "PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding UTF8" on user input email fields in both development and in a staging environment on Heroku. Downgrading to Ruby 2.1.5 with no other changes fixed the issue completely.

update:

Beat to the punch on this update but the bug does not lie in Ruby but rather the pg gem: https://github.com/ged/ruby-pg/pull/5

like image 35
Fred Guest Avatar answered Sep 28 '22 07:09

Fred Guest