Callback collision #1777

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
10 participants
@mandrews

Rebased version of previous pull request see:
#269

@sikachu

This comment has been minimized.

Show comment Hide comment
@sikachu

sikachu Jun 20, 2011

Member

@josevalim bro, review please :)

Member

sikachu commented Jun 20, 2011

@josevalim bro, review please :)

@bgentry

This comment has been minimized.

Show comment Hide comment
@bgentry

bgentry Jun 20, 2011

Contributor

@mandrews thanks for staying on top of this. Looking forward to seeing this merged before 3.1

Contributor

bgentry commented Jun 20, 2011

@mandrews thanks for staying on top of this. Looking forward to seeing this merged before 3.1

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim Jun 22, 2011

Contributor

Thanks for the pull request but I am a bit afraid of this having collateral effects. For example, the options :only and :except used in controllers are not removed from the options hash, so we can have different behavior after applying this commit as callbacks will be no longer considered identical just by their name.

That is just example, we may have other cases.

Contributor

josevalim commented Jun 22, 2011

Thanks for the pull request but I am a bit afraid of this having collateral effects. For example, the options :only and :except used in controllers are not removed from the options hash, so we can have different behavior after applying this commit as callbacks will be no longer considered identical just by their name.

That is just example, we may have other cases.

@bgentry

This comment has been minimized.

Show comment Hide comment
@bgentry

bgentry Jun 22, 2011

Contributor

@josevalim in the other pull request, @mandrews mentioned this as a possibility which you liked:

@josevalim- I agree that hard coding :on is not appropriate. How about instead of white listing options that imply difference, we black list options that determine equivalence.

In this case, how would you like that to be implemented? I really want a fix for this issue to be included in the next releases so I'm willing to spend some time to make that happen in the next day or 2.

Contributor

bgentry commented Jun 22, 2011

@josevalim in the other pull request, @mandrews mentioned this as a possibility which you liked:

@josevalim- I agree that hard coding :on is not appropriate. How about instead of white listing options that imply difference, we black list options that determine equivalence.

In this case, how would you like that to be implemented? I really want a fix for this issue to be included in the next releases so I'm willing to spend some time to make that happen in the next day or 2.

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim Jun 22, 2011

Contributor

@bgentry Yeah, I remember that. Although I could see such flaws just after looking at your pull request as I saw :per_key and remembered of :only and :except. I think our best option would be to allow :on => [:create, :update] or something similar, which I believe I also commented on the other thread. Sorry for the back and forth.

Contributor

josevalim commented Jun 22, 2011

@bgentry Yeah, I remember that. Although I could see such flaws just after looking at your pull request as I saw :per_key and remembered of :only and :except. I think our best option would be to allow :on => [:create, :update] or something similar, which I believe I also commented on the other thread. Sorry for the back and forth.

@sikachu

This comment has been minimized.

Show comment Hide comment
@sikachu

sikachu Jul 11, 2011

Member

What's the status of this bro @josevalim?

Member

sikachu commented Jul 11, 2011

What's the status of this bro @josevalim?

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim Jul 11, 2011

Contributor

The status is the same as in my last comment. :)

Contributor

josevalim commented Jul 11, 2011

The status is the same as in my last comment. :)

@isaacsanders

This comment has been minimized.

Show comment Hide comment
@isaacsanders

isaacsanders Apr 28, 2012

Contributor

@mandrews Is this still an issue?

Contributor

isaacsanders commented Apr 28, 2012

@mandrews Is this still an issue?

@mandrews

This comment has been minimized.

Show comment Hide comment
@mandrews

mandrews May 20, 2012

@isaacsanders without the changes the unit test still fails on master. If the approach to fixing the issue is OK I can easily make another pull request (git pull --rebase fails).

@isaacsanders without the changes the unit test still fails on master. If the approach to fixing the issue is OK I can easily make another pull request (git pull --rebase fails).

@frodsan

This comment has been minimized.

Show comment Hide comment
@frodsan

frodsan Sep 12, 2012

Contributor

@josevalim any news?

Contributor

frodsan commented Sep 12, 2012

@josevalim any news?

@frodsan

This comment has been minimized.

Show comment Hide comment
@frodsan

frodsan Sep 20, 2012

Contributor

@steveklabnik Can we close it and keep it with #6936?

Contributor

frodsan commented Sep 20, 2012

@steveklabnik Can we close it and keep it with #6936?

@steveklabnik

This comment has been minimized.

Show comment Hide comment
@steveklabnik

steveklabnik Sep 20, 2012

Member

I think so, but let's wait until SOMETHING gets accepted before we get close-happy.

Member

steveklabnik commented Sep 20, 2012

I think so, but let's wait until SOMETHING gets accepted before we get close-happy.

@spastorino

This comment has been minimized.

Show comment Hide comment
@spastorino

spastorino Sep 24, 2012

Member

I've merged #6936 can we close this now?

Member

spastorino commented Sep 24, 2012

I've merged #6936 can we close this now?

@steveklabnik

This comment has been minimized.

Show comment Hide comment
@steveklabnik

steveklabnik Sep 24, 2012

Member

Seems so!

Member

steveklabnik commented Sep 24, 2012

Seems so!

@kulbida

This comment has been minimized.

Show comment Hide comment
@kulbida

kulbida Dec 23, 2012

Found this issue...
I have a code something like

class User < ActiveRecord::Base
  ...
  before_validation(:on => :create) {:set_current_ratio}
  before_validation(:on => :create) {:set_free_until }
  ...
end

What I'm getting with User._validation_callbacks.map(&:filter) is ["_callback_before_779", "_callback_before_783"]
What is this _callback_before_783 and why I can't get a name like set_current_ratio of the callback?
Thanks.

kulbida commented Dec 23, 2012

Found this issue...
I have a code something like

class User < ActiveRecord::Base
  ...
  before_validation(:on => :create) {:set_current_ratio}
  before_validation(:on => :create) {:set_free_until }
  ...
end

What I'm getting with User._validation_callbacks.map(&:filter) is ["_callback_before_779", "_callback_before_783"]
What is this _callback_before_783 and why I can't get a name like set_current_ratio of the callback?
Thanks.

@kulbida

This comment has been minimized.

Show comment Hide comment
@kulbida

kulbida Dec 23, 2012

  before_validation :set_current_ratio, :on => :create
  before_validation :set_free_until, :on => :create

did the magic but why this

  before_validation(:on => :create) {:set_current_ratio}
  before_validation(:on => :create) {:set_free_until }

doesn't work?

kulbida commented Dec 23, 2012

  before_validation :set_current_ratio, :on => :create
  before_validation :set_free_until, :on => :create

did the magic but why this

  before_validation(:on => :create) {:set_current_ratio}
  before_validation(:on => :create) {:set_free_until }

doesn't work?

@pixeltrix

This comment has been minimized.

Show comment Hide comment
@pixeltrix

pixeltrix Dec 23, 2012

Member

@kulbida because you're passing a block in the former example - you need to call the methods directly:

before_validation(:on => :create){ set_current_ratio }
before_validation(:on => :create){ set_free_until }

For your own benefit in the future you'd be better off asking questions either on the Rails Talk mailing list or Stack Overflow since you're more likely to have a positive response than adding a comment to an issue that was closed three months ago.

Member

pixeltrix commented Dec 23, 2012

@kulbida because you're passing a block in the former example - you need to call the methods directly:

before_validation(:on => :create){ set_current_ratio }
before_validation(:on => :create){ set_free_until }

For your own benefit in the future you'd be better off asking questions either on the Rails Talk mailing list or Stack Overflow since you're more likely to have a positive response than adding a comment to an issue that was closed three months ago.

@kulbida

This comment has been minimized.

Show comment Hide comment
@kulbida

kulbida Dec 23, 2012

Thank you :)

kulbida commented Dec 23, 2012

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment