abraham
(Abraham Raji)
June 19, 2023, 1:14pm
1
Hey folks,
First time contributor here.
I am trying to run specs and all the specs are failing with the following error:
ActiveRecord::InvalidForeignKey:
PG::ForeignKeyViolation: ERROR: insert or update on table "aspect_memberships" violates foreign key constraint "aspect_memberships_aspect_id_fk"
DETAIL: Key (aspect_id)=(10) is not present in table "aspects".
I have followed the steps mention here . Please let me know any further information is required to debug this.
denschub
(Dennis Schubert)
June 19, 2023, 4:24pm
2
Interesting, that almost sounds like there is some invalid data in your test database, as that should never happen, as diaspora creates all the needed entities before running spec, fixing them in place.
What I’d try is to “start from fresh”. i.e., first, delete all the locally generated test fixtures with
git clean -fx spec/fixtures/
and then re-create the database with
RAILS_ENV="test" bin/rake db:drop db:prepare
Then run all the specs once with bin/rake spec
. If it still fails, please share the entire test output.
abraham
(Abraham Raji)
June 19, 2023, 5:55pm
3
RAILS_ENV="test" bin/rake db:drop db:prepare
This failed with the following error:
WARNING: Namespace test not found in /home/avronr/worksapce/diaspora/config/diaspora.toml
The Jasmine Ruby gems are deprecated. There will be no further releases after
the end of the Jasmine 3.x series. We recommend that most users migrate to the
jasmine-browser-runner npm package, which is the direct replacement for the
jasmine gem. See <https://jasmine.github.io/setup/browser.html> for setup
instructions, including for Rails applications that use either Sprockets or
Webpacker.
If jasmine-browser-runner doesn't meet your needs, one of these might:
* The jasmine npm package to run specs in Node.js:
<https://github.com/jasmine/jasmine-npm>
* The standalone distribution to run specs in browsers with no additional
tools: <https://github.com/jasmine/jasmine#installation>
* The jasmine-core npm package if all you need is the Jasmine assets:
<https://github.com/jasmine/jasmine>. This is the direct equivalent of the
jasmine-core Ruby gem.
To prevent this message from appearing, set the SUPPRESS_JASMINE_DEPRECATION
environment variable.
rake aborted!
ActiveRecord::NoEnvironmentInSchemaError:
Environment data not found in the schema. To resolve this issue, run:
bin/rails db:environment:set RAILS_ENV=test
Tasks: TOP => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
denschub
(Dennis Schubert)
June 19, 2023, 5:57pm
4
Yeah, that’s fine.
bin/rails db:environment:set RAILS_ENV=test
prior to the db:drop
will do the job.
abraham
(Abraham Raji)
June 19, 2023, 6:26pm
5
The output is too long and I’m hitting limits on pastebins.
But this is sort of a sample output (the error is the same for all tests):
4017) making sure the spec runner works #post creates a notification with a mention
Failure/Error: @connection.async_exec(sql)
ActiveRecord::InvalidForeignKey:
PG::ForeignKeyViolation: ERROR: insert or update on table "aspect_memberships" violates foreign key constraint "aspect_memberships_aspect_id_fk"
DETAIL: Key (aspect_id)=(17) is not present in table "aspects".
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `exec'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `block (2 levels) in execute'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block in execute'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `execute'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:131:in `execute_batch'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:413:in `block (3 levels) in insert_fixtures_set'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:412:in `block (2 levels) in insert_fixtures_set'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/referential_integrity.rb:19:in `disable_referential_integrity'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:411:in `block in insert_fixtures_set'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:523:in `with_multi_statements'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:410:in `insert_fixtures_set'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/fixtures.rb:638:in `block in insert'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/fixtures.rb:629:in `each'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/fixtures.rb:629:in `insert'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/fixtures.rb:615:in `read_and_insert'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/fixtures.rb:567:in `create_fixtures'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/test_fixtures.rb:268:in `load_fixtures'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/test_fixtures.rb:122:in `setup_fixtures'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/test_fixtures.rb:10:in `before_setup'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-rails-5.1.2/lib/rspec/rails/adapters.rb:74:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:390:in `execute_with'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:352:in `call'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:390:in `execute_with'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:352:in `call'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:486:in `run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:259:in `run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:646:in `block in run_examples'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:642:in `map'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:642:in `run_examples'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:607:in `run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `block in run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `map'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `map'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/configuration.rb:2068:in `with_suite_hooks'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:116:in `block in run_specs'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/reporter.rb:74:in `report'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:115:in `run_specs'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:89:in `run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:71:in `run'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:45:in `invoke'
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/exe/rspec:4:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ------------------
# --- Caused by: ---
# PG::ForeignKeyViolation:
# ERROR: insert or update on table "aspect_memberships" violates foreign key constraint "aspect_memberships_aspect_id_fk"
# DETAIL: Key (aspect_id)=(17) is not present in table "aspects".
# /home/avronr/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `exec'
WARNING: Rails was not able to disable referential integrity.================================================== 98 ====================================================================================================> | ETA: 00:00:02
This is most likely caused due to missing permissions.
Rails needs superuser privileges to disable referential integrity.
cause: PG::InsufficientPrivilege: ERROR: permission denied: "RI_ConstraintTrigger_a_26615" is a system trigger
denschub
(Dennis Schubert)
June 19, 2023, 6:31pm
6
well, yeah, check the output
WARNING: Rails was not able to disable referential integrity.
This is most likely caused due to missing permissions.
Rails needs superuser privileges to disable referential integrity.
To properly run tests and set up the database into the testable state, the database user to run tests needs superuser permissions.
For Postgres, open a psql shell as the postgres
user and run
ALTER USER [username here] WITH SUPERUSER;
Or, alternatively, just connect to your database as the postgres
user, which is the default in our database.yml
. This isn’t awesome in production, but perfectly fine in development.