jeremyevans / sequel

Sequel: The Database Toolkit for Ruby
http://sequel.jeremyevans.net
Other
4.99k stars 1.07k forks source link

Objects being saved more often on update to 5.62.0 #1961

Closed drstrangelooker closed 1 year ago

drstrangelooker commented 2 years ago

I have a model pointing to a MariaDB 8.0 database.

My tests look like this...

    it 'must associate items' do
      folder = create(:folder)
      other_folder = create(:folder)

      expect(folder.items).must_equal([])

      item1 = create(:item, :folder_id => folder[:id])
      item2 = create(:item, :folder_id => other_folder[:id])
      item3 = create(:item, :folder_id => folder[:id])

      folder.refresh
      expect(folder.items.size).must_equal(2)

      expect(folder.items).must_include(item1)
      expect(folder.items).wont_include(item2)
      expect(folder.items).must_include(item3)
    end

This works fine with Sequel 4.49.0. It fails with 5.62.0.

When I look at why it is failing, some timestamps are differing.

In 4.49.0, I dump the values of the timestamps and get this

updated_at
1668031114.7697651
1668031114.7697651
indexed_at
1668031114.7698472
1668031114.7698472

With the more recent version I get the following:

updated_at
doesn't match
1668030765.372529
1668030765.355943
indexed_at
doesn't match
1668030765.372633
1668030765.3560069

The before_save method for item does reference these columns:

      def before_save
        self[:updated_at] = Time.now
        self[:indexed_at] = Time.now
        super
      end

So it is possible that this is getting called now, but wasn't in the older version.

Any ideas?

drstrangelooker commented 2 years ago

It looks like the before_save method is getting called. The following works

      # setup snipped

      item1 = create(:item, :folder_id => folder[:id])
      item2 = create(:item, :folder_id => other_folder[:id])
      item3 = create(:item, :folder_id => folder[:id])

      folder.refresh

      item1 = MyApp::Model::DBItem.where(:id => item1[:id]).first
      item2 = MyApp::Model::DBItem.where(:id => item2[:id]).first
      item3 = MyApp::Model::DBItem.where(:id => item3[:id]).first

      # tests snipped
jeremyevans commented 2 years ago

It's expected that before_save is called before saving. If you think there is an actual bug here, can you post a minimal self contained example showing it? As to why Sequel 4.49.0 operated differently, I couldn't tell you off hand.

jeremyevans commented 1 year ago

Closing this now. If you do think this is a bug and can create a minimal self contained example, please post it here so I can review and potentially reopen.

drstrangelooker commented 1 year ago

I haven't had a chance to create a test case. When I do I'll reopen. Thanks.

On Thu, Nov 10, 2022, 7:12 PM Jeremy Evans @.***> wrote:

Closed #1961 https://github.com/jeremyevans/sequel/issues/1961 as completed.

— Reply to this email directly, view it on GitHub https://github.com/jeremyevans/sequel/issues/1961#event-7787966723, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSDEENDWLNQNTKU5OD4MT3WHWFODANCNFSM6AAAAAAR35K7TA . You are receiving this because you authored the thread.Message ID: @.***>