Fix ActiveJob::SerializationError: Unsupported argument type: Symbol in Rails
This error occurs when you pass an argument to an ActiveJob that cannot be serialized by the job serializer. ActiveJob uses GlobalID for models and JSON serialization for primitives. Symbols, procs, and complex objects cannot be serialized. Convert symbols to strings and pass simple types or GlobalID-capable models.
Reading the Stack Trace
Here's what each line means:
- activejob (7.1.3) lib/active_job/arguments.rb:80:in `serialize_argument': ActiveJob cannot serialize the Symbol type into a format suitable for the queue backend.
- activejob (7.1.3) lib/active_job/enqueuing.rb:42:in `enqueue': The error occurs when the job is being enqueued, not when it runs.
- app/controllers/reports_controller.rb:12:in `generate': The controller action attempts to enqueue a job with a Symbol argument.
Common Causes
1. Passing a symbol to perform_later
Symbols cannot be serialized to JSON for the job queue backend.
class ReportJob < ApplicationJob
def perform(report_type)
Report.generate(report_type)
end
end
# Controller
ReportJob.perform_later(:monthly) # Symbol is not serializable
2. Passing a proc or lambda
Procs and lambdas cannot be serialized and sent to a queue backend.
NotificationJob.perform_later(-> { User.active })
3. Passing a non-GlobalID object
Complex objects that do not include GlobalID::Identification cannot be serialized.
data = OpenStruct.new(name: 'report', type: 'pdf')
ExportJob.perform_later(data)
The Fix
Convert the symbol to a string before passing it to perform_later. Inside the job, convert it back to a symbol if needed. Strings are JSON-serializable and work with all queue backends.
ReportJob.perform_later(:monthly)
ReportJob.perform_later('monthly')
# In the job:
class ReportJob < ApplicationJob
def perform(report_type)
Report.generate(report_type.to_sym)
end
end
Testing the Fix
require 'rails_helper'
RSpec.describe ReportJob, type: :job do
describe '#perform' do
it 'enqueues with a string argument' do
expect {
ReportJob.perform_later('monthly')
}.to have_enqueued_job(ReportJob).with('monthly')
end
it 'generates the correct report type' do
expect(Report).to receive(:generate).with(:monthly)
ReportJob.perform_now('monthly')
end
end
end
Run your tests:
bundle exec rspec spec/jobs/report_job_spec.rb
Pushing Through CI/CD
git checkout -b fix/rails-serialization-error,git add app/jobs/report_job.rb app/controllers/reports_controller.rb,git commit -m "fix: convert symbol to string for ActiveJob serialization",git push origin fix/rails-serialization-error
Your CI config should look something like this:
name: CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports: ['5432:5432']
redis:
image: redis:7
ports: ['6379:6379']
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- run: bin/rails db:setup
- run: bundle exec rspec
The Full Manual Process: 18 Steps
Here's every step you just went through to fix this one bug:
- Notice the error alert or see it in your monitoring tool
- Open the error dashboard and read the stack trace
- Identify the file and line number from the stack trace
- Open your IDE and navigate to the file
- Read the surrounding code to understand context
- Reproduce the error locally
- Identify the root cause
- Write the fix
- Run the test suite locally
- Fix any failing tests
- Write new tests covering the edge case
- Run the full test suite again
- Create a new git branch
- Commit and push your changes
- Open a pull request
- Wait for code review
- Merge and deploy to production
- Monitor production to confirm the error is resolved
Total time: 30-60 minutes. For one bug.
Or Let bugstack Fix It in Under 2 minutes
Every step above? bugstack does it automatically.
Step 1: Install the SDK
gem install bugstack
Step 2: Initialize
require 'bugstack'
Bugstack.init(api_key: ENV['BUGSTACK_API_KEY'])
Step 3: There is no step 3.
bugstack handles everything from here:
- Captures the stack trace and request context
- Pulls the relevant source files from your GitHub repo
- Analyzes the error and understands the code context
- Generates a minimal, verified fix
- Runs your existing test suite
- Pushes through your CI/CD pipeline
- Deploys to production (or opens a PR for review)
Time from error to fix deployed: Under 2 minutes.
Human involvement: zero.
Try bugstack Free →No credit card. 5-minute setup. Cancel anytime.
Deploying the Fix (Manual Path)
- Replace all symbol arguments in job enqueue calls with strings.
- Update jobs to convert strings back to symbols inside perform.
- Run job specs to confirm serialization works.
- Open a pull request.
- Merge and verify jobs process correctly in staging.
Frequently Asked Questions
BugStack runs the fix through your existing test suite, generates additional edge-case tests, and validates that no other components are affected before marking it safe to deploy.
BugStack never pushes directly to production. Every fix goes through a pull request with full CI checks, so your team can review it before merging.
ActiveJob supports strings, integers, floats, booleans, nil, arrays, hashes with string keys, Date, Time, DateTime, BigDecimal, and ActiveRecord models via GlobalID.
Yes, ActiveRecord models are serialized via GlobalID automatically. The job receives the model's ID and reloads it from the database when performing.