shakacode / cypress-on-rails

Use cypress.io or playwright.dev with your rails application. This Ruby gem lets you use your regular Rails test setup and clean-up, such as FactoryBot.
MIT License
417 stars 61 forks source link

ApplicationRecord Load getting Mysql Error #155

Open markhermano opened 8 months ago

markhermano commented 8 months ago

Hello,

I stumbled into another issue here which only occurs again on CI but works locally. The gem loads the resource for the ApplicationRecord model but doesn't find a DB table associated with it.

The error I get in GitHub actions is: image

Here is the test.log from the Github actions artifacts:

[CY_DEV]   ItemToProcess Load (0.6ms)  SELECT `items_to_process`.* FROM `items_to_process` LIMIT 100
[CY_DEV]   LabelDisplay Load (0.5ms)  SELECT `label_displays`.* FROM `label_displays` LIMIT 100
[CY_DEV]   LeadsDetail Load (0.6ms)  SELECT `leads_details`.* FROM `leads_details` LIMIT 100
[CY_DEV]   ApplicationRecord Load (0.5ms)  SELECT ``.* FROM `` LIMIT 100
[CY_DEV] fail to execute /app/spec-cypress/e2e/app_commands/log_fail.rb: Mysql2::Error: Incorrect table name ''
[CY_DEV] /app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:151:in `_query'
/app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:151:in `block in query'
/app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:150:in `handle_interrupt'
/app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:150:in `query'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:201:in `block (2 levels) in execute'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:200:in `block in execute'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:728:in `block (2 levels) in log'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:727:in `block in log'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `log'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:199:in `execute'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:210:in `execute_and_free'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/mysql/database_statements.rb:46:in `exec_query'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:489:in `select'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/query_cache.rb:105:in `block in select_all'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/query_cache.rb:122:in `block in cache_sql'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/query_cache.rb:113:in `cache_sql'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/query_cache.rb:105:in `select_all'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/mysql/database_statements.rb:12:in `select_all'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/querying.rb:46:in `find_by_sql'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/relation.rb:824:in `block in exec_queries'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/relation.rb:842:in `skip_query_cache_if_necessary'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/relation.rb:811:in `exec_queries'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/relation.rb:626:in `load'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/relation.rb:250:in `records'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.6.1/lib/active_record/relation/delegation.rb:88:in `each'
/app/spec-cypress/e2e/app_commands/log_fail.rb:16:in `map'
/app/spec-cypress/e2e/app_commands/log_fail.rb:16:in `block in perform'
/app/spec-cypress/e2e/app_commands/log_fail.rb:15:in `each'
/app/spec-cypress/e2e/app_commands/log_fail.rb:15:in `each_with_object'
/app/spec-cypress/e2e/app_commands/log_fail.rb:15:in `perform'
/app/vendor/bundle/ruby/3.0.0/gems/cypress-on-rails-1.16.0/lib/cypress_on_rails/command_executor.rb:9:in `eval'
/app/vendor/bundle/ruby/3.0.0/gems/cypress-on-rails-1.16.0/lib/cypress_on_rails/command_executor.rb:9:in `perform'
/app/vendor/bundle/ruby/3.0.0/gems/cypress-on-rails-1.16.0/lib/cypress_on_rails/middleware.rb:61:in `block in handle_command'
/app/vendor/bundle/ruby/3.0.0/gems/cypress-on-rails-1.16.0/lib/cypress_on_rails/middleware.rb:61:in `map'
/app/vendor/bundle/ruby/3.0.0/gems/cypress-on-rails-1.16.0/lib/cypress_on_rails/middleware.rb:61:in `handle_command'
/app/vendor/bundle/ruby/3.0.0/gems/cypress-on-rails-1.16.0/lib/cypress_on_rails/middleware.rb:20:in `block in call'

Is there a workaround for this issue?

markhermano commented 8 months ago

I found a solution to the issue above by doing the following in log_fail.rb but I'm unsure if this is a better way of doing it.

json_result["records"] =
    (ActiveRecord::Base.descendants - [ApplicationRecord]).each_with_object({}) do |record_class, records|
      records[record_class.to_s] = record_class.limit(100).map(&:attributes)
    rescue StandardError => e
      raise e
    end