Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

NoMethodError: undefined method 'state' for nil:NilClass

Đang mở
#692 8 bình luận 10 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
32/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
postgresql, rails, ruby
Lĩnh vực
databases, testing

Hướng nghiên cứu

Bắt đầu với spec/rails_helper.rb:77 và transaction.rb:17 gây lỗi được hiển thị trong stack trace, sau đó tái hiện lỗi không liên tục bằng thiết lập Ruby, Rails, PostgreSQL và GitHub Actions đã được báo cáo. Thêm một bài kiểm thử hồi quy cho trường hợp transaction nil và xác minh rằng bộ kiểm thử hoàn tất ổn định mà không có NoMethodError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Ruby
Star
3k
Fork
485
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DatabaseCleaner/database_cleaner

Tất cả issue của DatabaseCleaner/database_cleaner

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.