Error when trying to run forked canvas-lms in GitHub Codespace: TypeError: Post is not a class

346 Views Asked by At

I am attempting to run instructure’s canvas-lms through GitHub codespace and am encountering the following issue. I am using the free 4 core plan. The repository and instructions for the codespace setupcan be found here. Has anyone run into this issue after using bundle exec rails canvas:compile_assets while trying to run their forked canvas-lms in GitHub codespace? I should be able to run bundle exec rails db:initial_setup after doing so to receive a prompt for authentication.

I run the following commands:

sudo apt-get update
sudo apt-get -y install postgresql-12 zlib1g-dev libldap2-dev libidn11-dev libxml2-dev libsqlite3-dev libpq-dev libxmlsec1-dev curl build-essential

rvm install "ruby-2.7.0"
rvm use 2.7.0
gem install bundle
gem install bundler:2.3.26
gem install nokogumbo scrypt sanitize ruby-debug-ide
sudo chown -R codespace:codespace /workspaces/canvas-lms/
sudo chown -R codespace:codespace /usr/local/rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0
bundle _2.3.26_ install
yarn install --pure-lockfile
for config in amazon_s3 delayed_jobs domain file_store outgoing_mail security external_migration dynamic_settings database; \
do cp -v config/$config.yml.example config/$config.yml; done
bundle _2.3.26_ update
sudo chown -R codespace:codespace /var/run/postgresql/
export PGHOST=localhost
/usr/lib/postgresql/12/bin/initdb \~/postgresql-data/ -E utf8
/usr/lib/postgresql/12/bin/pg_ctl -D \~/postgresql-data/ -l \~/postgresql-data/server.log start
/usr/lib/postgresql/12/bin/createdb canvas_development
bundle exec rails canvas:compile_assets

**At this point the following error is thrown:

Top level ::CompositeIO is deprecated, require 'multipart/post' and use `Multipart::Post::CompositeReadIO` instead!
Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!
/usr/local/rvm/gems/ruby-2.7.0/gems/faraday-0.17.4/lib/faraday/upload_io.rb:65: warning: constant ::UploadIO is deprecated
/usr/local/rvm/gems/ruby-2.7.0/gems/faraday-0.17.4/lib/faraday/upload_io.rb:66: warning: constant ::Parts is deprecated
rails aborted!
TypeError: Post is not a class

When I run bundle exec rails canvas:compile_assets –trace, the following is shown:

Top level ::CompositeIO is deprecated, require 'multipart/post' and use `Multipart::Post::CompositeReadIO` instead!
Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!
/usr/local/rvm/gems/ruby-2.7.0/gems/faraday-0.17.4/lib/faraday/upload_io.rb:65: warning: constant ::UploadIO is deprecated
/usr/local/rvm/gems/ruby-2.7.0/gems/faraday-0.17.4/lib/faraday/upload_io.rb:66: warning: constant ::Parts is deprecated
rails aborted!
TypeError: Post is not a class
/usr/local/rvm/gems/ruby-2.7.0/gems/multipart-post-2.3.0/lib/multipart/post/parts.rb:25: previous definition of Post was here
/workspaces/canvas-lms/gems/multipart/lib/multipart/post.rb:23:in `<module:Multipart>' /workspaces/canvas-lms/gems/multipart/lib/multipart/post.rb:22:in `\<main\>'
/usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/rvm/gems/ruby-2.7.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require' /workspaces/canvas-lms/gems/multipart/lib/multipart.rb:40:in `\<module:Multipart\>'
/workspaces/canvas-lms/gems/multipart/lib/multipart.rb:35:in `<main>' /usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
/workspaces/canvas-lms/gems/canvas_kaltura/lib/canvas_kaltura/kaltura_client_v3.rb:26:in `<main>' /usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
/workspaces/canvas-lms/gems/canvas_kaltura/lib/canvas_kaltura.rb:24:in `<module:CanvasKaltura>' /workspaces/canvas-lms/gems/canvas_kaltura/lib/canvas_kaltura.rb:23:in `\<main\>'
/usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/rvm/gems/ruby-2.7.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/bundler-2.3.26/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
/usr/local/rvm/gems/ruby-2.7.0/gems/bundler-2.3.26/lib/bundler/runtime.rb:55:in `each' /usr/local/rvm/gems/ruby-2.7.0/gems/bundler-2.3.26/lib/bundler/runtime.rb:55:in `block in require'
/usr/local/rvm/gems/ruby-2.7.0/gems/bundler-2.3.26/lib/bundler/runtime.rb:44:in `each' /usr/local/rvm/gems/ruby-2.7.0/gems/bundler-2.3.26/lib/bundler/runtime.rb:44:in `require'
/usr/local/rvm/gems/ruby-2.7.0/gems/bundler-2.3.26/lib/bundler.rb:186:in `require' /workspaces/canvas-lms/config/application.rb:28:in `\<main\>'
/usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/workspaces/canvas-lms/Rakefile:6:in `<main>' /usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/rake_module.rb:29:in `load'
/usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/rake_module.rb:29:in `load_rakefile' /usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/application.rb:703:in `raw_load_rakefile'
/usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/application.rb:104:in `block in load_rakefile' /usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/application.rb:103:in `load_rakefile' /usr/local/rvm/gems/ruby-2.7.0/gems/railties-7.0.3/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/usr/local/rvm/gems/ruby-2.7.0/gems/rake-13.0.3/lib/rake/rake_module.rb:59:in `with_application' /usr/local/rvm/gems/ruby-2.7.0/gems/railties-7.0.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/usr/local/rvm/gems/ruby-2.7.0/gems/railties-7.0.3/lib/rails/command.rb:51:in `invoke' /usr/local/rvm/gems/ruby-2.7.0/gems/railties-7.0.3/lib/rails/commands.rb:18:in `\<main\>'
/usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' /usr/local/rvm/gems/ruby-2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/workspaces/canvas-lms/bin/rails:16:in `<top (required)>' /usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/lib/spring/client/rails.rb:30:in `load'
/usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/lib/spring/client/rails.rb:30:in `call' /usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/lib/spring/client/command.rb:7:in `call'
/usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/lib/spring/client.rb:30:in `run' /usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/bin/spring:49:in `\<top (required)\>'
/usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/lib/spring/binstub.rb:11:in `load' /usr/local/rvm/gems/ruby-2.7.0/gems/spring-4.0.0/lib/spring/binstub.rb:11:in `\<top (required)\>'
/workspaces/canvas-lms/bin/spring:21:in `require' /workspaces/canvas-lms/bin/spring:21:in `\<top (required)\>'
bin/rails:5:in `load' bin/rails:5:in `\<main\>'
2

There are 2 best solutions below

0
ConorEP On

I found a workaround. PLEASE do not take this as good advice - this is just something that worked for me when trying to get a dev Canvas environment running in a Github codespace. There's a strong potential for some sort of future errors that I have not come across yet, but this has been good enough for me to use a Canvas codespace for a development project.


I was seeing that Post is not a class error. It certainly is, but I searched for similar errors online and saw discussions regarding duplicated class names being a potential issue. Thus, I changed a few things.

  1. /workspaces/canvas-lms/gems/multipart/lib/multipart.rb
    • changed the line that requires 'post.rb' to 'posts.rb'
  2. /workspaces/canvas-lms/gems/multipart/lib/multipart/post.rb
    • changed this filename to 'posts.rb'
  3. /workspaces/canvas-lms/gems/multipart/lib/multipart/posts.rb
    • changed the class name from Post to Posts

I was able to run the canvas:compile_assets command again and was not getting the same error. HOWEVER, I got a NEW error after much of the compiling seemed to work. The error:

--> Finished: 'js:webpack_development' in 100.79s rails aborted! Parallel::UndumpableException: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "public.brand_configs" does not exist LINE 1: DELETE FROM "public"."brand_configs" WHERE (NOT EXISTS (SELE...
                    ^ /workspaces/canvas-lms/config/initializers/active_record.rb:1430:in `delete_all' /workspaces/canvas-lms/config/initializers/active_record.rb:1462:in `delete_all' /workspaces/canvas-lms/app/models/brand_config.rb:266:in `clean_unused_from_db!'

I again searched around for similar errors, finding this discussion: https://github.com/instructure/canvas-lms/issues/2023

The discussion gave me a command to test out:

COMPILE_ASSETS_BRAND_CONFIGS=0 RAILS_ENV=production bundle exec rake canvas:compile_assets


The command obviously says 'production,' but it got me through compile_assets just fine. I was able to initialize the DB with credentials, launch Canvas in the codespace, and have thusfar been able to use that for the development I'm working on.

0
Mike Szyndel On

The error TypeError: Post is not a class is caused by the fact that multipart-post gem defines Multipart::Post as a module since version 2.2.0.

hat you can try is lock version of this gem below 2.2.0 by changing the Gemfile to

gem 'multipart-post', '< 2.2.0'

but after searching the code I can't even tell where this dependency is defined. The project also runs on Ruby 2.7 and I'd personally stay away from it.