Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1.1
    • Fix Version/s: None
    • Component/s: Jobs
    • Labels:
      None

      Description

      Some of the scheduled jobs we create contain arrays in the job configuration hash. When serialising those arrays into an ActiveRecord object, the strings get serialised as base64, and they don't get deserialised correctly.

      This is the simplest possible way to replicate the issue:

      config = {
        one: 'hello',
        two: ['hello']
      }
      TorqueBox::ScheduledJob.at('DummyService', { at: Time.now, name: 'hi', config: config})
      

      And the following code in the service, including debugging information:

      class DummyService
        def initialize(params)
          params.each do |k,v|
            if v.class == String
              puts "String - #{k} #{v}"
            else
              puts "1. #{v.class} #{v.class.object_id} #{Array.object_id}"
              puts "2. #{k} #{v}"
            end
          end
          @params = params
        end
      
        def run
          ReportData.create!(shared_with: @params)
        end
      end
      

      where:

      class ReportData < ActiveRecord::Base
        serialize :shared_with
      end
      

      The debug output from the puts statements is:

      String - one hello
      1. Array 14306 14308
      2. two ["hello"]
      

      Note in the second output line that, although the class is an array, the object id of the Array that arrives in the parameters is different from that of an Array in the class.

      The result of the create! method is:

      INSERT INTO `report_data` (..., `shared_with`, ...) VALUES (..., '---\n:one: hello\n:two: !ruby/array:Array\n- !ruby/string:String |-\n aGVsbG8=\n...)
      

      where aGVsbG8 is base64 for 'hello'
      If the service runs this code instead:

      ReportData.create(shared_with: {one: 'hello', two: ['hello']})
      

      It all runs fine and it generates the following SQL:

      INSERT INTO `report_data` (..., `shared_with`, ...) VALUES (..., '---\n:one: hello\n:two:\n- hello\n', ...)
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                diego.alonso.fluid Diego Alonso
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: