Project

General

Profile

Bug #2671

Encoding problem with ruby1.9 and UTF-8

Added by Romain Vrignaud about 9 years ago. Updated about 5 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:

Description

Since I upgraded my Foreman instance from
Squeeze to Wheezy, I can't save anymore some templates :

I get following errors in my logs :
Operation FAILED: incompatible character encodings: ASCII-8BIT and UTF-8
Rendered home/_topbar.rhtml (4.6ms)
Rendered common/500.rhtml within layouts/application (13.1ms)
Completed 500 Internal Server Error in 135ms (Views: 14.0ms | ActiveRecord: 11.8ms)

In my apache's vhost configuration I had and still have :
AddDefaultCharset UTF-8

History

#1 Updated by Dominic Cleal about 9 years ago

Which database do you use?

Can you check the character set of the database and the tables?

#2 Updated by Romain Vrignaud about 9 years ago

I'm using Mysql

My database.yml :
production:
adapter: mysql
database: foreman
host: xxx
port:
username: xxx
password: xxx
encoding: utf8

mysql> show variables like "character_set_database" \G
  • 1. row *******************
    Variable_name: character_set_database
    Value: latin1
mysql> show full columns from config_templates \G
  • 1. row *******************
    Field: id
    Type: int(11)
    Collation: NULL
    Null: NO
    Key: PRI
    Default: NULL
    Extra: auto_increment
    Privileges: select,insert,update,references
    Comment:
  • 2. row *******************
    Field: name
    Type: varchar(255)
    Collation: latin1_swedish_ci
    Null: YES
    Key:
    Default: NULL
    Extra:
    Privileges: select,insert,update,references
    Comment:
  • 3. row *******************
    Field: template
    Type: text
    Collation: latin1_swedish_ci
    Null: YES
    Key:
    Default: NULL
    Extra:
    Privileges: select,insert,update,references
    Comment:
  • 4. row *******************
    Field: snippet
    Type: tinyint(1)
    Collation: NULL
    Null: YES
    Key:
    Default: NULL
    Extra:
    Privileges: select,insert,update,references
    Comment:
  • 5. row *******************
    Field: template_kind_id
    Type: int(11)
    Collation: NULL
    Null: YES
    Key:
    Default: NULL
    Extra:
    Privileges: select,insert,update,references
    Comment:
  • 6. row *******************
    Field: created_at
    Type: datetime
    Collation: NULL
    Null: YES
    Key:
    Default: NULL
    Extra:
    Privileges: select,insert,update,references
    Comment:
  • 7. row *******************
    Field: updated_at
    Type: datetime
    Collation: NULL
    Null: YES
    Key:
    Default: NULL
    Extra:
    Privileges: select,insert,update,references
    Comment:

#3 Updated by Dominic Cleal about 9 years ago

I wish I could point to exactly what's wrong, but these errors in my experience are hard to debug. I'd suggest trying to make everything use UTF-8, which means updating the database, the tables and the columns in MySQL, they each have their own collation settings (http://dev.mysql.com/doc/refman/5.0/en/charset-syntax.html).

#4 Updated by Romain Vrignaud about 9 years ago

I never managed those database/tables by hand. It has always been managed with puppet/stored_config and foreman ActiveRecords.
Could that be done in a db:migrate task ?

#5 Updated by Dominic Cleal about 9 years ago

Quite probably, yes. It'd be useful to know if it solves the problem first though.

#6 Updated by Romain Vrignaud about 9 years ago

We just realized that users with non asccii character in their name are
not able to use foreman anymore because foreman throw 500 error even on /hosts page.
Our users come from LDAP backend and I can't resave a user with non ascii character in fields.
If I try to save with é or è characters I get Last Name field 'is invalid'.
IMHO this is a big problem and for us Foreman does not support properly ruby1.9
if we have no configuration mistake.

#7 Updated by Soungalo SIDIBE about 9 years ago

Hello ,
I've got the same problem, any solutions ?

#8 Updated by Soungalo SIDIBE about 9 years ago

if you had this error due at an user's import from LDAP.
go in to your database and drop the users with non carcaters utf-8 on their name.

and next to this you can do this

First, to solve the error caused by MySQL I used this two articles :

http://www.dotkam.com/2008/09/14/configure-rails-and-mysql-to-support-utf-8/

http://www.rorra.com.ar/2010/07/30/rails-3-mysql-and-utf-8/

Second, to solve the file encoding problem I added these 2 lines in my config/environment.rb

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

#9 Updated by Patrick Martins almost 9 years ago

Hello,

I've got the same problem. Just upgraded my Squeeze to Wheezy and now I got some errors when I click on edit node.

Encoding::CompatibilityError
incompatible character encodings: UTF-8 and ASCII-8BIT
app/helpers/layout_helper.rb:108:in `block in selectable_f'
app/helpers/layout_helper.rb:132:in `block (2 levels) in field'
app/helpers/layout_helper.rb:131:in `block in field'
app/helpers/layout_helper.rb:124:in `field'
app/helpers/layout_helper.rb:107:in `selectable_f'
app/views/hosts/_form.html.erb:96:in `block (2 levels) in app_views_hosts_form_html_erb__2240670598635151677_66412540'
app/helpers/layout_helper.rb:211:in `form_for'
app/views/hosts/_form.html.erb:7:in `block in app_views_hosts_form_html_erb__2240670598635151677_66412540'
app/models/taxonomy.rb:55:in `block (2 levels) in as_taxonomy'
lib/foreman/thread_session.rb:140:in `as_location'
app/models/taxonomy.rb:54:in `block in as_taxonomy'
lib/foreman/thread_session.rb:105:in `as_org'
app/models/taxonomy.rb:53:in `as_taxonomy'
app/views/hosts/_form.html.erb:5:in `_app_views_hosts__form_html_erb__2240670598635151677_66412540'
app/views/hosts/edit.html.erb:7:in `_app_views_hosts_edit_html_erb___1719025858547709970_67454920'
lib/foreman/thread_session.rb:31:in `clear_thread'

Are they any solutions?

#10 Updated by Anonymous about 5 years ago

  • Description updated (diff)
  • Status changed from New to Resolved

Ruby 2.0 uses UTF-8 by default everywhere

Also available in: Atom PDF