Permalink
Browse files

Refactor Model not to rely on return value of _refresh

Instead, have lock! and refresh return self manually.  This makes
plugins easier, as they don't have to worry about returning the
value of super.  This fixes an issue with the dirty plugin not
having refresh return self.  Thanks to viking for the heads up.
  • Loading branch information...
1 parent 8cbb3c4 commit 1808d49f880bf9b823f9e5b800e24bed277820cb @jeremyevans committed May 1, 2012
Showing with 4 additions and 4 deletions.
  1. +3 −2 lib/sequel/model/base.rb
  2. +1 −2 lib/sequel/plugins/composition.rb
View
5 lib/sequel/model/base.rb
@@ -1106,7 +1106,8 @@ def keys
# a.update(...)
# end
def lock!
- new? ? self : _refresh(this.for_update)
+ _refresh(this.for_update) unless new?
+ self
end
# Remove elements of the model object that make marshalling fail. Returns self.
@@ -1185,6 +1186,7 @@ def pk_hash
def refresh
raise Sequel::Error, "can't refresh frozen object" if frozen?
_refresh(this)
+ self
end
# Alias of refresh, but not aliased directly to make overriding in a plugin easier.
@@ -1532,7 +1534,6 @@ def _insert_select_raw(ds)
def _refresh(dataset)
set_values(_refresh_get(dataset) || raise(Error, "Record not found"))
changed_columns.clear
- self
end
# Get the row of column data from the database.
View
3 lib/sequel/plugins/composition.rb
@@ -150,9 +150,8 @@ def define_composition_accessor(name, opts={})
module InstanceMethods
# Clear the cached compositions when refreshing.
def _refresh(ds)
- v = super
+ super
compositions.clear
- v
end
# For each composition, set the columns in the model class based

5 comments on commit 1808d49

@rosenfeld

Could you please release a new version including this commit? This change since the previous version has changed my specs...

@jeremyevans
Owner

This isn't a regression (the dirty plugin was just introduced in the latest version), and I generally do not do point releases except to fix regressions or very serious issues in new features. While it's unfortunate that 3.35.0 shipped with this bug, I don't think it's significant enough to warrant releasing 3.35.1. 3.36.0 will be released June 1, so you won't have to wait that long for a fix.

@rosenfeld

Fortunately Bundler will allow me to use your master branch until there :)

@rosenfeld

By the way, I remember a day where Rails has released two minor versions in the same day, so I don't really understand strict rules for release dates :)

@jeremyevans
Owner

Well, Rails has a lot of developers working on it, whereas Sequel is mostly just me. Also, the two releases in the same day was because Rails released a completely broken release first, and then had to issue another release to fix it. That's not really the case here.

I understand the issue affected you, and I'm sorry for that. Your recent pull request will help ensure that a similar bug does not occur in the future, and I thank you for that.

Please sign in to comment.