All my tables/models have a "revision" field, and I have a
before_update callback to increment the revision field.

Among my tables are:
   events
   rooms
   events_rooms

In my Event model, I have:
   has_many :eventRooms
   has_many(:rooms, :through => :eventRooms)

When I create an event, assign a room or two, and then save, the
"events_rooms" table entry is initially created with a revision of 1,
and then (immediately, automatically, and inexplicably) updated to have
a revision of 2. I do not want every new record to have a revision
number of 2. The revision 2 version is identical to revision 1 (which
it replaces), aside from the revision number.

I can reproduce this in the rails console with the following:
   event = Event.new({'name' => 'Meeting 5'})
   event.rooms << Room.find(['1', '2'])
   event.save

Does anyone have any idea why this could be happening or where I should
look for further troubleshooting?

I'm working trying to strip out all the weird stuff (there's a lot) that
I had in my app, and remove anything proprietary so I can make a simple
test case.
So far, none of my simplifications have made this problem go away.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141015170156.d51ede1ce4b44572de20ce20%40brisammon.fastmail.fm.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Brian Sammon at Oct 16, 2014 at 1:58 pm
    Oh, yeah, and the standard details:
    Rails 4.1.6
    MariaDB
    SuSE Linux

    On Wed, 15 Oct 2014 17:01:56 -0400
    Brian Sammon wrote:
    All my tables/models have a "revision" field, and I have a
    before_update callback to increment the revision field.

    Among my tables are:
    events
    rooms
    events_rooms

    In my Event model, I have:
    has_many :eventRooms
    has_many(:rooms, :through => :eventRooms)

    When I create an event, assign a room or two, and then save, the
    "events_rooms" table entry is initially created with a revision of 1,
    and then (immediately, automatically, and inexplicably) updated to have
    a revision of 2. I do not want every new record to have a revision
    number of 2. The revision 2 version is identical to revision 1 (which
    it replaces), aside from the revision number.

    I can reproduce this in the rails console with the following:
    event = Event.new({'name' => 'Meeting 5'})
    event.rooms << Room.find(['1', '2'])
    event.save

    Does anyone have any idea why this could be happening or where I should
    look for further troubleshooting?

    I'm working trying to strip out all the weird stuff (there's a lot) that
    I had in my app, and remove anything proprietary so I can make a simple
    test case.
    So far, none of my simplifications have made this problem go away.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141015170156.d51ede1ce4b44572de20ce20%40brisammon.fastmail.fm.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141016095816.c2a08c9b66d79c9d3b03264b%40brisammon.fastmail.fm.
    For more options, visit https://groups.google.com/d/optout.
  • Brian Sammon at Oct 16, 2014 at 5:48 pm

    On Thu, 16 Oct 2014 09:58:16 -0400 Brian Sammon wrote:
    All my tables/models have a "revision" field, and I have a
    before_update callback to increment the revision field.

    Among my tables are:
    events
    rooms
    events_rooms

    In my Event model, I have:
    has_many :eventRooms
    has_many(:rooms, :through => :eventRooms)

    When I create an event, assign a room or two, and then save, the
    "events_rooms" table entry is initially created with a revision of 1,
    and then (immediately, automatically, and inexplicably) updated to hav
    a revision of 2. I do not want every new record to have a revision
    number of 2. The revision 2 version is identical to revision 1 (which
    it replaces), aside from the revision number.
    My workaround is to do my before_update as follows:
         before_update :incr_rev

         private
         def incr_rev
           if changed?
             self.revision = self.revision + 1
           end
         end

    With this workaround, it still calls the before_update callback when I
    create a new record, but doesn't actually do an update.

    I'm baffled that it would be calling the before_update callback if it's
    not changed, but it does.

    Starting to wonder if I've found a bug.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141016134846.9dcdbe4bb5df8eb48b7ae15b%40brisammon.fastmail.fm.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Oct 16, 2014 at 6:59 pm

    On 15 October 2014 22:01, Brian Sammon wrote:
    All my tables/models have a "revision" field, and I have a
    before_update callback to increment the revision field.

    Among my tables are:
    events
    rooms
    events_rooms

    In my Event model, I have:
    has_many :eventRooms
    has_many(:rooms, :through => :eventRooms)

    When I create an event, assign a room or two, and then save, the
    "events_rooms" table entry is initially created with a revision of 1,
    and then (immediately, automatically, and inexplicably) updated to have
    a revision of 2. I do not want every new record to have a revision
    number of 2. The revision 2 version is identical to revision 1 (which
    it replaces), aside from the revision number.

    I can reproduce this in the rails console with the following:
    event = Event.new({'name' => 'Meeting 5'})
    event.rooms << Room.find(['1', '2'])
    event.save

    Does anyone have any idea why this could be happening or where I should
    look for further troubleshooting?
    Just to be clear you are saying that the above code invokes
    before_update once where you would not expect it to be called at all?
    If so is it invoked by the save or does it get called when the room is
    added?

    Does it save it twice?

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs5yb-k-dW%2Bve1VXRFfMBQLfjZ_P_Frk1wNXS1cS0KZOQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Brian Sammon at Oct 16, 2014 at 7:14 pm

    On Thu, 16 Oct 2014 19:58:52 +0100 Colin Law wrote:

    On 15 October 2014 22:01, Brian Sammon
    wrote:
    All my tables/models have a "revision" field, and I have a
    before_update callback to increment the revision field.

    Among my tables are:
    events
    rooms
    events_rooms

    In my Event model, I have:
    has_many :eventRooms
    has_many(:rooms, :through => :eventRooms)

    When I create an event, assign a room or two, and then save, the
    "events_rooms" table entry is initially created with a revision of 1,
    and then (immediately, automatically, and inexplicably) updated to hav
    a revision of 2. I do not want every new record to have a revision
    number of 2. The revision 2 version is identical to revision 1 (which
    it replaces), aside from the revision number.

    I can reproduce this in the rails console with the following:
    event = Event.new({'name' => 'Meeting 5'})
    event.rooms << Room.find(['1', '2'])
    event.save

    Does anyone have any idea why this could be happening or where I shoul
    look for further troubleshooting?
    Just to be clear you are saying that the above code invokes
    before_update once where you would not expect it to be called at all?
    If so is it invoked by the save or does it get called when the room is
    added?

    Does it save it twice?
    it does a sql INSERT followed by a sql UPDATE (both) after "event.save".

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141016151405.a39b45767754d32af364e563%40brisammon.fastmail.fm.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Oct 16, 2014 at 7:57 pm

    On 16 October 2014 20:14, Brian Sammon wrote:
    On Thu, 16 Oct 2014 19:58:52 +0100
    Colin Law wrote:
    On 15 October 2014 22:01, Brian Sammon
    wrote:
    All my tables/models have a "revision" field, and I have a
    before_update callback to increment the revision field.

    Among my tables are:
    events
    rooms
    events_rooms

    In my Event model, I have:
    has_many :eventRooms
    has_many(:rooms, :through => :eventRooms)

    When I create an event, assign a room or two, and then save, the
    "events_rooms" table entry is initially created with a revision of 1,
    and then (immediately, automatically, and inexplicably) updated to hav
    a revision of 2. I do not want every new record to have a revision
    number of 2. The revision 2 version is identical to revision 1 (which
    it replaces), aside from the revision number.

    I can reproduce this in the rails console with the following:
    event = Event.new({'name' => 'Meeting 5'})
    event.rooms << Room.find(['1', '2'])
    event.save

    Does anyone have any idea why this could be happening or where I shoul
    look for further troubleshooting?
    Just to be clear you are saying that the above code invokes
    before_update once where you would not expect it to be called at all?
    If so is it invoked by the save or does it get called when the room is
    added?

    Does it save it twice?
    it does a sql INSERT followed by a sql UPDATE (both) after "event.save".
    Strictly it will be during event.save call (before the UPDATE).
    Presumably it is adding the room that is triggering the problem. It
    does look like a bug to me. Do you know whether it happened with
    earlier versions of Rails? If not then almost certainly a bug.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvkpbZo25CezDAMCCsG5gZVFes4wahHUCZDQvWm4s8n4Q%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Brian Sammon at Oct 16, 2014 at 8:16 pm

    On Thu, 16 Oct 2014 20:56:28 +0100 Colin Law wrote:

    Strictly it will be during event.save call (before the UPDATE).
    Presumably it is adding the room that is triggering the problem. It
    does look like a bug to me. Do you know whether it happened with
    earlier versions of Rails? If not then almost certainly a bug.
    Dunno... the only versions of Rails that I've ever used are 1.something
    and 4.1.6.

    Well, I've created an issue in the rails issue tracker. We shall see.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141016161635.303ca010909cab3566d2f8d4%40brisammon.fastmail.fm.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Oct 16, 2014 at 8:52 pm

    On 16 October 2014 21:16, Brian Sammon wrote:
    On Thu, 16 Oct 2014 20:56:28 +0100
    Colin Law wrote:
    Strictly it will be during event.save call (before the UPDATE).
    Presumably it is adding the room that is triggering the problem. It
    does look like a bug to me. Do you know whether it happened with
    earlier versions of Rails? If not then almost certainly a bug.
    Dunno... the only versions of Rails that I've ever used are 1.something
    and 4.1.6.

    Well, I've created an issue in the rails issue tracker. We shall see.
    Can you post a link please?

    Thanks

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLukhsSv%3D9pAzzeaSg9zwU1hVOyEEvKZVSq__RspNx4KNA%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Brian Sammon at Oct 16, 2014 at 9:29 pm

    On Thu, 16 Oct 2014 21:51:53 +0100 Colin Law wrote:
    Well, I've created an issue in the rails issue tracker. We shall see.
    Can you post a link please?
    https://github.com/rails/rails/issues/17289

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141016172948.c3328444360d4fa90288aef3%40brisammon.fastmail.fm.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 15, '14 at 9:02p
activeOct 16, '14 at 9:29p
posts9
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Brian Sammon: 6 posts Colin Law: 3 posts

People

Translate

site design / logo © 2022 Grokbase