ledermann / unread

Handle unread records and mark them as read with Ruby on Rails
MIT License
739 stars 121 forks source link

Rails 7.2.1 issue. ArgumentError: wrong number of arguments #135

Open yunixon opened 2 months ago

yunixon commented 2 months ago

Get error with rails 7.2.1

@alert.mark_as_read! for: @current_user

ArgumentError: wrong number of arguments (given 1, expected 2)

return to rails 7.1.4 and works good

Diff:

Using activesupport 7.2.1 (was 7.1.4)
Using activemodel 7.2.1 (was 7.1.4)
Using activerecord 7.2.1 (was 7.1.4)
Using activejob 7.2.1 (was 7.1.4)
Using actionview 7.2.1 (was 7.1.4)
Using actionpack 7.2.1 (was 7.1.4)
Using actionmailer 7.2.1 (was 7.1.4)
Using railties 7.2.1 (was 7.1.4)
Using actioncable 7.2.1 (was 7.1.4)
Using activestorage 7.2.1 (was 7.1.4)
Using actiontext 7.2.1 (was 7.1.4)
Using actionmailbox 7.2.1 (was 7.1.4)
Using rails 7.2.1 (was 7.1.4)
ledermann commented 2 months ago

Fixes for Rails 7.2 are not released yet. Please try this:

gem 'unread', github: 'ledermann/unread'
chriswnl commented 1 month ago

7.2 support now seems to be there but I'm getting issues caused by the precision on timestamp on ReadMark vs datetime on my rails models.

This only came to light in dev while immediately marking an issue read under :show in the controller. That creates a timestamp on the read_mark without milliseconds while the datetime column on the model supports milliseconds.

This results in the read_mark appearing to be created before the associated record.


[#<ReadMark:0x0000717b61e4f798
  id: 9,
  readable_type: "Issue",
  readable_id: 6,
  reader_type: "User",
  reader_id: 1,
  timestamp: "2024-10-09 10:00:53.000000000 +0000">] 
3.3.1 :011 > i
 => 
#<Issue:0x0000717b621acf80
 id: 6,
 subject: "test this please",
 description: "let's see",
 user_id: 1,
 created_at: "2024-10-09 10:00:53.231852000 +0000",
 updated_at: "2024-10-09 10:00:53.231852000 +0000"> 

My fix was to change the migration adding precision: 6

def self.up
  create_table ReadMark, force: true, options: create_options do |t|
    t.references :readable, polymorphic: { null: false }
    t.references :reader,   polymorphic: { null: false }
    t.datetime :timestamp, null: false, precision: 6
  end

  add_index ReadMark, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true
end
smgdkngt commented 1 month ago

If someone is looking for a migration for the solution from @chriswnl:

class AddPrecisionToReadMarks < ActiveRecord::Migration[8.0]
  def change
    change_column :read_marks, :timestamp, :datetime, precision: 6
  end
end

Maybe unrelated to this, but with Rails 8 I also ran into issues when immediately marking a created entity as read. For now I manually increase the timestamp by 1 second 🫤

current_user.read_marks.where(readable: things).update_all("timestamp = timestamp + interval '1 seconds'")

I'm using postgres btw.