NoMethodError: undefined method 'state' for nil:NilClass
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 32/100
调研方向
从堆栈跟踪中显示的 spec/rails_helper.rb:77 和失败的 transaction.rb:17 开始,然后使用所报告的 Ruby、Rails、PostgreSQL 和 GitHub Actions 设置重现间歇性故障。为 nil transaction 情况添加回归测试,并验证测试套件能够可靠地完成且不会出现 NoMethodError。
由索引模型根据 Issue 内容生成。
描述
Setup
- Ruby: 3.1.2
- Rails: 7.0.3.1
- PostgreSQL: 14.4
- OS: Ubuntu 20.04.4 LTS on WSL2
- GitHub Actions:
- Image: ubuntu-latest
- PostgreSQL: 14.2
---
Gemfile.lock:
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
Error
From time to time, if a run my specs locally it might throw the error below, the fun thing is it errors for like two or three runs and then it passes (using same seed at all times);
This error also occurs occasionally on GitHub Actions, I have to re-run my workflow some times as well to make it pass (different seeds)
$ rspec spec/
Failure/Error:
DatabaseCleaner.cleaning do
example.run
end
NoMethodError:
undefined method `state' for nil:NilClass
transaction.rollback unless transaction.state.invalidated?
^^^^^^
# /home/lucas/.rvm/gems/ruby-3.1.2@perk-api-sch/gems/database_cleaner-active_record-2.0.1/lib/database_cleaner/active_record/transaction.rb:17:in `block in clean'
# /home/lucas/.rvm/gems/ruby-3.1.2@perk-api-sch/gems/database_cleaner-active_record-2.0.1/lib/database_cleaner/active_record/transaction.rb:15:in `each'
# /home/lucas/.rvm/gems/ruby-3.1.2@perk-api-sch/gems/database_cleaner-active_record-2.0.1/lib/database_cleaner/active_record/transaction.rb:15:in `clean'
# /home/lucas/.rvm/gems/ruby-3.1.2@perk-api-sch/gems/database_cleaner-core-2.0.1/lib/database_cleaner/strategy.rb:32:in `cleaning'
# /home/lucas/.rvm/gems/ruby-3.1.2@perk-api-sch/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:34:in `block (2 levels) in cleaning'
# /home/lucas/.rvm/gems/ruby-3.1.2@perk-api-sch/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:35:in `cleaning'
# ./spec/rails_helper.rb:77:in `block (2 levels) in <top (required)>'
Database Cleaner Config
DatabaseCleaner.strategy = :transaction
DatabaseCleaner[:active_record].clean_with :truncation, {
except: %w(
table_a
table_b
table_c
)
}
config.around do |example|
DatabaseCleaner.cleaning do
example.run
end
end
Any idea what might be causing this error and how to fix it?
Thanks for the gem and your attention.
- 主要语言
- Ruby
- 星标
- 3k
- 派生
- 484
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DatabaseCleaner/database_cleaner 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 67/100
-
难度 4/5 3-5 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 35/100
DatabaseCleaner/database_cleaner#717 · 5 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 25/100
DatabaseCleaner/database_cleaner#716 · 2 条评论 ·
查看 DatabaseCleaner/database_cleaner 的全部 Issue
相似的 Issue
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memory可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
area/web interface
难度 2/5 1-3 小时 新手友好度 62/100
mastodon/mastodon#41000 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
zerocracy/judges-action#2743 ·
维护者通常 8 天内回复
-
Python 3.15 support可能已有人在做 @amnesiaof 今天认领。 未关闭L: python L: python:uv
难度 2/5 1-3 小时 新手友好度 72/100
dependabot/dependabot-core#16524 · 1 条评论 ·
维护者通常 1 天内回复
-
content good first issue
难度 2/5 1-3 小时 新手友好度 66/100
rubyevents/rubyevents#2182 ·
维护者通常 1 天内回复