tdfowler@pacbell.net
2006-Dec-20 16:38 UTC
Ticket #6825: AR serialized attributes don''t work with Oracle CLOB.
Hi,
New to Rails (love it!), and contributing bug reports/patches but here
goes....
We are working with rails edge using Oracle. We are using migrations
to create
tables with that have columns of type :text - which get mapped to an
Oracle CLOB type.
We then have ActiveRecord models that use the serialize feature on
these columns..ie.
class User < ActiveRecord::Base
serialize :preferences
end
When you attempt to do a save on this you will get exceptions (when
using Oracle,
not mysql)
The problem seems to be in oracle_adapter.rb, which uses an after_save
filter to
handle the writing of the CLOB:
# After setting large objects to empty, select the OCI8::LOB
# and write back the data.
after_save :write_lobs
def write_lobs() #:nodoc:
if connection.is_a?(ConnectionAdapters::OracleAdapter)
self.class.columns.select { |c| c.sql_type =~ /LOB$/i }.each {
|c|
value = self[c.name]
next if value.nil? || (value == '''')
lob = connection.select_one(
"SELECT #{c.name} FROM #{self.class.table_name} WHERE
#{self.class.primary_key} = #{quote_value(id)}",
''Writable Large Object'')[c.name]
lob.write value
}
end
end
The "lob.write value" call does not take into account that
"value" may
be a serialized attribute. To fix this I changed "lob.write value" to:
lob.write self.class.serialized_attributes[c.name] ? value.to_yaml :
value
I am not entirely certain that doing "value.to_yaml" is the best way
to
get at the serialized representation of an attribute but it works for
my code.
Tom
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael A. Schoen
2006-Dec-26 23:05 UTC
Re: Ticket #6825: AR serialized attributes don''t work with Oracle CLOB.
tdfowler@pacbell.net wrote:> The "lob.write value" call does not take into account that "value" may > be a serialized attribute. To fix this I changed "lob.write value" to: > > lob.write self.class.serialized_attributes[c.name] ? value.to_yaml : > value > > I am not entirely certain that doing "value.to_yaml" is the best way to > get at the serialized representation of an attribute but it works for > my code.Would you be able to provide a failing ActiveRecord test for this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
tdfowler@pacbell.net
2006-Dec-27 18:40 UTC
Re: Ticket #6825: AR serialized attributes don''t work with Oracle CLOB.
Michael A. Schoen wrote:> tdfowler@pacbell.net wrote: > > The "lob.write value" call does not take into account that "value" may > > be a serialized attribute. To fix this I changed "lob.write value" to: > > > > lob.write self.class.serialized_attributes[c.name] ? value.to_yaml : > > value > > > > I am not entirely certain that doing "value.to_yaml" is the best way to > > get at the serialized representation of an attribute but it works for > > my code. > > Would you be able to provide a failing ActiveRecord test for this?Sure... Here is my test case: ----serialize_test.rb------ require ''abstract_unit'' class Notification < ActiveRecord::Base serialize :n_conditions end class SerializeTest < Test::Unit::TestCase self.use_transactional_fixtures = false def setup ActiveRecord::Base.connection.create_table :notifications do |t| t.column :n_conditions, :text t.column :emails_sent, :integer, :limit => 6, :default => 0 end end def teardown ActiveRecord::Base.connection.drop_table :notifications end def test_write_serialized_attribute1 notification = Notification.new notification.n_conditions = ["this should work"] notification.save end def test_write_serialized_attribute2 notification = Notification.new notification.n_conditions = "this should work" notification.save end end ----- When I execute this with: ruby -I "connections/native_oracle" serialize_test.rb I get the following output: Using Oracle Loaded suite serialize_test Started E. Finished in 0.26515 seconds. 1) Error: test_write_serialized_attribute1(SerializeTest): TypeError: wrong argument type Array (expected String) /home/fowleth/bin/ruby/lib/ruby/site_ruby/1.8/oci8.rb:813:in `write'' /home/fowleth/bin/ruby/lib/ruby/site_ruby/1.8/oci8.rb:813:in `write'' ./../lib/active_record/connection_adapters/oracle_adapter.rb:55:in `write_lobs'' ./../lib/active_record/connection_adapters/oracle_adapter.rb:49:in `each'' ./../lib/active_record/connection_adapters/oracle_adapter.rb:49:in `write_lobs'' ./../lib/active_record/callbacks.rb:333:in `send'' ./../lib/active_record/callbacks.rb:333:in `callback'' ./../lib/active_record/callbacks.rb:330:in `each'' ./../lib/active_record/callbacks.rb:330:in `callback'' ./../lib/active_record/callbacks.rb:243:in `create_or_update'' ./../lib/active_record/base.rb:1533:in `save_without_validation'' ./../lib/active_record/validations.rb:749:in `save_without_transactions'' ./../lib/active_record/transactions.rb:129:in `save'' ./../lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'' ./../lib/active_record/transactions.rb:95:in `transaction'' ./../lib/active_record/transactions.rb:121:in `transaction'' ./../lib/active_record/transactions.rb:129:in `save'' serialize_test.rb:27:in `test_write_serialized_attribute1'' 2 tests, 0 assertions, 0 failures, 1 errors --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Nick Sieger
2006-Dec-27 19:59 UTC
Re: Ticket #6825: AR serialized attributes don''t work with Oracle CLOB.
On 12/27/06, tdfowler@pacbell.net <tdfowler@pacbell.net> wrote:> > > > Michael A. Schoen wrote: > > tdfowler@pacbell.net wrote: > > > The "lob.write value" call does not take into account that "value" may > > > be a serialized attribute. To fix this I changed "lob.write value" to: > > > > > > lob.write self.class.serialized_attributes[c.name] ? value.to_yaml : > > > value > > > > > > I am not entirely certain that doing "value.to_yaml" is the best way > to > > > get at the serialized representation of an attribute but it works for > > > my code. > > > > Would you be able to provide a failing ActiveRecord test for this? > > Sure... > > Here is my test case:If this is reasonable (seems like it is -- Michael), could you attach a new patch to the ticket and raise it on the other thread (RC2 imminent)? Would be a nice fix to have in 1.2, as I have a patched oracle adapter to deal with the same issue. /Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
http://dev.rubyonrails.org/ticket/6825 AR serialized attributes don''t work with Oracle CLOB Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
done, thanks! On 1/6/07, Michael A. Schoen <schoenm@earthlink.net> wrote:> > http://dev.rubyonrails.org/ticket/6825 > AR serialized attributes don''t work with Oracle CLOB > > Thanks! > > > >-- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Michael and Koz! /Nick On 1/5/07, Michael Koziarski <michael@koziarski.com> wrote:> > > done, thanks! > > On 1/6/07, Michael A. Schoen <schoenm@earthlink.net> wrote: > > > > http://dev.rubyonrails.org/ticket/6825 > > AR serialized attributes don''t work with Oracle CLOB > > > > Thanks! > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---