gocardless / statesman

A statesmanlike state machine library.
https://gocardless.com/blog/statesman/
MIT License
1.78k stars 163 forks source link

`TypeError: can't quote Hash` when running transition table migration #313

Open ollieh-m opened 6 years ago

ollieh-m commented 6 years ago

When I run rails g statesman:active_record_transition Order OrderTransition, the migration created includes t.text :metadata, default: {}. This line causes the migration to fail with the error TypeError: can't quote Hash

Changing the line to t.json :metadata, default: {} allows the migration to complete.

Seems the migration generator shouldn't be defaulting the column to type text.

Rails 5.1.5 Statesman 3.4.1

timrogers commented 6 years ago

I have a suspicion that this might be adapted for how an older versions of Rails works. I’ll check when I get a chance! On Fri, 9 Mar 2018 at 21:53, Ollie Haydon-Mulligan notifications@github.com wrote:

When I run rails g statesman:active_record_transition Order OrderTransition, the migration created includes t.text :metadata, default: {}. This line causes the migration to fail with the error TypeError: can't quote Hash

Changing the line to t.json :metadata, default: {} allows the migration to complete.

Seems the migration generator shouldn't be defaulting the column to type text.

Rails 5.1.5 Statesman 3.4.1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gocardless/statesman/issues/313, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHFplY9kom0YiGDrt0dDA4iLh2nV8Khks5tcvnLgaJpZM4Sk690 .

ewlarson commented 6 years ago

I saw the same issue here. Fixed it locally by quoting the empty hash: t.text :metadata, default: "{}"

I'm on MySQL here, so we cannot opt for the json column type.

t3k4y commented 6 years ago

@ollieh-m same here, using @ewlarson s fixx since with json i'm getting the following Transition#metadata column type cannot be json and serialized simultaneously. If you are using a json column type, it is not necessary to include Statesman::Adapters::ActiveRecordTransition