drwl / annotaterb

A Ruby Gem that adds annotations to your Rails models and route files.
Other
195 stars 18 forks source link

JSON parse error #155

Open saturnflyer opened 2 months ago

saturnflyer commented 2 months ago

I haven't yet identified the cause but I updated to the 4.12 this week and discovered that my Rails 7.1 application cannot migrate.

Removing the gem fixes this.

Commands

> rails db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke db:load_config
** Execute db:schema:dump
** Invoke environment
Annotating models
bin/rails aborted!
TypeError: no implicit conversion of nil into String (TypeError)

    Parser.new(source, **(opts||{})).parse
               ^^^^^^^^^^^^^^^^^^^^
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/json-2.7.2/lib/json/common.rb:220:in `initialize'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/json-2.7.2/lib/json/common.rb:220:in `new'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/json-2.7.2/lib/json/common.rb:220:in `parse'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activesupport-7.1.4/lib/active_support/json/decoding.rb:23:in `decode'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activerecord-7.1.4/lib/active_record/type/serialized.rb:64:in `default_value?'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activerecord-7.1.4/lib/active_record/type/serialized.rb:19:in `deserialize'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activemodel-7.1.4/lib/active_model/attribute.rb:175:in `type_cast'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activemodel-7.1.4/lib/active_model/attribute.rb:43:in `value'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activemodel-7.1.4/lib/active_model/attribute_set.rb:37:in `block in to_hash'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activesupport-7.1.4/lib/active_support/core_ext/enumerable.rb:78:in `block in index_with'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activesupport-7.1.4/lib/active_support/core_ext/enumerable.rb:78:in `each'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activesupport-7.1.4/lib/active_support/core_ext/enumerable.rb:78:in `index_with'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activemodel-7.1.4/lib/active_model/attribute_set.rb:37:in `to_hash'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/activerecord-7.1.4/lib/active_record/model_schema.rb:499:in `column_defaults'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/model_wrapper.rb:62:in `column_defaults'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb:19:in `build'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb:51:in `block in columns'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb:50:in `map'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb:50:in `columns'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb:25:in `body'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb:34:in `build'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb:79:in `build'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/project_annotator.rb:42:in `build_instructions_for_file'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/project_annotator.rb:17:in `block in annotate'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/project_annotator.rb:13:in `map'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/project_annotator.rb:13:in `annotate'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotator.rb:21:in `do_annotations'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/model_annotator/annotator.rb:8:in `do_annotations'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/commands/annotate_models.rb:17:in `call'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/runner.rb:24:in `run'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/runner.rb:7:in `run'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/annotaterb-4.12.0/lib/annotate_rb/tasks/annotate_models_migrate.rake:32:in `block (3 levels) in <main>'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/command.rb:156:in `invoke_rake'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/command.rb:73:in `block in invoke'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/command.rb:149:in `with_argv'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/command.rb:69:in `invoke'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.1.4/lib/rails/commands.rb:18:in `<main>'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/Users/jim/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate

Version

saturnflyer commented 2 months ago

This was caused by a recent change in our code on a serialized column. Switching from

serialize :summary, coder: ActiveSupport::JSON

to

serialize :summary, coder: YAML, type: Hash

fixed this for us. We have legacy data in YAML and were in the process of switching it to JSON. It seems like this might still be a bug because the serialize that trigged this is a valid model configuration.

drwl commented 1 month ago

Hi @saturnflyer thanks for submitting an issue and apologies for the super long delay in response. I've been trying address issues in the order in which they came.

Would you be able to make a dummy rails app where I could reproduce the issue? Something like this would be very helpful: https://github.com/drwl/annotaterb/issues/149#issuecomment-2364406635