Ruby on rails 在Rails中保存后添加到属性的奇怪字节
我们正在经历一个疯狂的错误,在保存电子邮件时,90%的时间似乎是随机字节被添加到电子邮件字段上。以下是可能发生的情况的示例: From params: 'user@example.com' Before validate: 'user@example.com' After validate: 'user@example.com' Before save: 'user@example.com' Value in object after save: 'user@example.com' Retrieve record just created by id, and fetch id: 'user@example.com\u007f' 有时我会得到完全无用的位,我无法判断是否有比这些字节更多的字节,因为Ruby on rails 在Rails中保存后添加到属性的奇怪字节,ruby-on-rails,ruby,postgresql,utf-8,Ruby On Rails,Ruby,Postgresql,Utf 8,我们正在经历一个疯狂的错误,在保存电子邮件时,90%的时间似乎是随机字节被添加到电子邮件字段上。以下是可能发生的情况的示例: From params: 'user@example.com' Before validate: 'user@example.com' After validate: 'user@example.com' Before save: 'user@example.com' Value in object after save: 'user@example.com' Retri
PG::CharacterNotInRepertoire
错误:
0xde 0x4d
0xf6 0x7f
0xbc
0xe3 0x6c 0x24
考虑到发生的PG::CharacterNotInRepertoire
错误,我假设这发生在值保存之前的某个地方,但超出了我的应用程序代码的范围
请注意,奇怪的是,对于用户的任何其他字段都不会发生这种情况
以下是当前涉及电子邮件地址的所有回调:
#脱衣代码>和
#downcase代码>验证前
- 使用正则表达式进行格式验证
\A[A-Za-z0-9.\%+-]+@(?[A-Za-z0-9-]+\)+[A-Za-z]{2,20}\z
- Ruby v2.2.0
- Rails v4.1.8
- 博士后9.3.2版
- 第v0.17.1页
pg ruby
立即升级或获取位。还请注意,如果您使用的是Rails 4.2.0,则pg 0.18.*存在影响写入二进制数据的问题。我目前有4.2.0版本的monkey,补丁将出现在4.2.1版本中。如果您使用Ruby 2.2运行4.2.0(因此使用pg 0.18),请参阅以了解详细信息。Rails 4.0上可能存在类似的问题。和4.1.*-我还没有弄清楚哪个版本有补丁,以及这些版本是否已经发布 我的4.2.0猴子补丁如下所示:
# Should release in Rails 4.2.1
# PostgreSQL, Fix change detection caused by superfluous bytea unescaping
# See https://github.com/rails/rails/pull/17680
if Rails.version == '4.2.0'
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module OID # :nodoc:
class Bytea < Type::Binary # :nodoc:
def type_cast_from_database(value)
return if value.nil?
return value.to_s if value.is_a?(Type::Binary::Data)
PGconn.unescape_bytea(super)
end
end
end
end
end
end
end
#应在Rails 4.2.1中发布
#PostgreSQL,修复因多余bytea而导致的更改检测
#看https://github.com/rails/rails/pull/17680
如果Rails.version=='4.2.0'
模块活动记录
模块连接适配器
PostgreSQL模块
模块OID#:nodoc:
类Bytea
# Should release in Rails 4.2.1
# PostgreSQL, Fix change detection caused by superfluous bytea unescaping
# See https://github.com/rails/rails/pull/17680
if Rails.version == '4.2.0'
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module OID # :nodoc:
class Bytea < Type::Binary # :nodoc:
def type_cast_from_database(value)
return if value.nil?
return value.to_s if value.is_a?(Type::Binary::Data)
PGconn.unescape_bytea(super)
end
end
end
end
end
end
end