Open
Conversation
Bumps [sequel](https://github.com/jeremyevans/sequel) from 5.100.0 to 5.101.0. - [Changelog](https://github.com/jeremyevans/sequel/blob/master/CHANGELOG) - [Commits](jeremyevans/sequel@5.100.0...5.101.0) --- updated-dependencies: - dependency-name: sequel dependency-version: 5.101.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Contributor
4 similar comments
Contributor
Contributor
Contributor
Contributor
Contributor
gem compare sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT version:
5.100.0: 5.100.0
5.101.0: 5.101.0
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb +164/-0
* Changed:
lib/sequel/dataset/actions.rb +9/-0
lib/sequel/version.rb +1/-1 |
2 similar comments
Contributor
gem compare sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT version:
5.100.0: 5.100.0
5.101.0: 5.101.0
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb +164/-0
* Changed:
lib/sequel/dataset/actions.rb +9/-0
lib/sequel/version.rb +1/-1 |
Contributor
gem compare sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT version:
5.100.0: 5.100.0
5.101.0: 5.101.0
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb +164/-0
* Changed:
lib/sequel/dataset/actions.rb +9/-0
lib/sequel/version.rb +1/-1 |
Contributor
gem compare --diff sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb
--- /tmp/20260202-1692-9d7noa 2026-02-02 03:32:52.324074148 +0000
+++ /tmp/d20260202-1692-qd1ndi/sequel-5.101.0/lib/sequel/plugins/detect_unnecessary_association_options.rb 2026-02-02 03:32:52.314074113 +0000
@@ -0,0 +1,164 @@
+# frozen-string-literal: true
+
+module Sequel
+ module Plugins
+ # The detect_unnecessary_association_options plugin can detect unnecessary
+ # association options, and either warn or raise if they are detected.
+ # This allows you to find and remove the unnecessary options.
+ # Association options are considered unnecessary if they specify the same
+ # value as Sequel's defaults.
+ #
+ # To detect unnecessary association options, you should load the plugin
+ # into your model base class (e.g. Sequel::Model) before loading your model
+ # classes. Then, after all models have been loaded, you can call the
+ # detect_unnecessary_association_options on each to check for unnecessary
+ # association options. Additionally, if you are calling finalize_associations,
+ # it will automatically check for unnecessary association options.
+ #
+ # A typical usage would be to combine this with the subclasses plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options
+ # Sequel::Model.plugin :subclasses
+ # # load model classes
+ #
+ # # implicitly check all subclasses when freezing descendants
+ # Sequel::Model.freeze_descendants
+ #
+ # # or, if not freezing all descendants
+ # Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
+ #
+ # By default, the plugin warns for every unnecessary association option.
+ # To raise an error instead, you can pass the <tt>action: :raise</tt> option when loading the
+ # plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
+ #
+ # This plugin only detects the most common unnecessary association options, such as:
+ #
+ # * :class (all associations)
+ # * :key and :primary_key (associations without join tables)
+ # * :join_table, :left_key, :right_key, :left_primary_key, :right_primary_key (single join table associations)
+ # * :left_primary_key, :right_primary_key (*_through_many associations)
+ #
+ # Only association types supported by default or supported by a plugin that
+ # ships with Sequel are supported by this plugin. Other association types are
+ # ignored.
+ module DetectUnnecessaryAssociationOptions
+ def self.configure(model, opts={})
+ model.instance_variable_set(:@detect_unnecessary_association_options_action, opts[:action] || :warn)
+ end
+
+ # Raised if the plugin action is to raise and an unnecessary association option
+ # is detected.
+ class UnnecessaryAssociationOption < Sequel::Error
+ end
+
+ module ClassMethods
+ Plugins.inherited_instance_variables(self, :@detect_unnecessary_association_options_action => nil)
+
+ # Implicitly check for unnecessary association options when finalizing associations.
+ def finalize_associations
+ res = super
+ detect_unnecessary_association_options
+ res
+ end
+
+ # Check for unnecessary association options.
+ def detect_unnecessary_association_options
+ @association_reflections.each_value do |ref|
+ meth = "detect_unnecessary_association_options_#{ref[:type]}"
+ # Expected to call private methods.
+ # Ignore unrecognized association types.
+ # External association types can define the appropriate method to
+ # support their own unnecessary association option checks.
+ if respond_to?(meth, true)
+ # All recognized association types need same class check
+ _detect_unnecessary_association_options_class(ref)
+ send(meth, ref)
+ end
+ end
+
+ nil
+ end
+
+ private
+
+ # Action to take if an unnecessary association option is detected.
+ def unnecessary_association_options_detected(ref, key)
+ if @detect_unnecessary_association_options_action == :raise
+ raise UnnecessaryAssociationOption, "#{ref.inspect} :#{key} option unnecessary"
+ else
+ warn "#{ref.inspect} :#{key} option unnecessary"
+ end
+ end
+
+ # Detect unnecessary :class option.
+ def _detect_unnecessary_association_options_class(ref)
+ return unless ref[:orig_class]
+
+ h = {}
+ name = ref[:name]
+ late_binding_class_option(h, ref.returns_array? ? singularize(name) : name)
+
+ begin
+ default_association_class = constantize(h[:class_name])
+ actual_association_class = ref.associated_class
+ rescue NameError
+ # Do not warn. For the default association class to not be a valid
+ # constant is expected. For the actual association class to not be
+ # a valid constant is not expected and a bug in the association, but
+ # the job of this plugin is not to detect invalid options, only
+ # unnecessary options.
+ else
+ if default_association_class.equal?(actual_association_class)
+ unnecessary_association_options_detected(ref, "class")
+ end
+ end
+ end
+
+ # Detect other unnecessary options. An option is considered unnecessary
+ # if the key was submitted as an association option and the value for
+ # the option is the same as the given value.
+ def _detect_unnecessary_association_options_key_value(ref, key, value)
+ if ref[:orig_opts].has_key?(key) && ref[:orig_opts][key] == value
+ unnecessary_association_options_detected(ref, key)
+ end
+ end
+
+ # Same as _detect_unnecessary_association_options_key_value, but calls
+ # the default_* method on the association reflection to get the default value.
+ def _detect_unnecessary_association_options_key(ref, key)
+ _detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}"))
+ end
+
+ def detect_unnecessary_association_options_many_to_one(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_pg_array_to_many detect_unnecessary_association_options_many_to_one
+
+ def detect_unnecessary_association_options_one_to_many(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, primary_key)
+ end
+ alias detect_unnecessary_association_options_one_to_one detect_unnecessary_association_options_one_to_many
+ alias detect_unnecessary_association_options_many_to_pg_array detect_unnecessary_association_options_one_to_many
+
+ def detect_unnecessary_association_options_many_to_many(ref)
+ [:join_table, :left_key, :right_key].each do |key|
+ _detect_unnecessary_association_options_key(ref, key)
+ end
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_one detect_unnecessary_association_options_many_to_many
+
+ def detect_unnecessary_association_options_many_through_many(ref)
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_many detect_unnecessary_association_options_many_through_many
+ end
+ end
+ end
+end
* Changed:
lib/sequel/dataset/actions.rb
--- /tmp/d20260202-1692-qd1ndi/sequel-5.100.0/lib/sequel/dataset/actions.rb 2026-02-02 03:32:52.252073898 +0000
+++ /tmp/d20260202-1692-qd1ndi/sequel-5.101.0/lib/sequel/dataset/actions.rb 2026-02-02 03:32:52.293074040 +0000
@@ -374,0 +375,9 @@
+ # The return value of this method is undefined and should not be used,
+ # except in two cases:
+ #
+ # * When the <tt>return: :primary_key</tt> option is used.
+ # * On PostgreSQL, when the dataset uses RETURNING. In this case, if
+ # a single value is returned per row, the return value is an array
+ # of those values. If multiple values are returned per row, the
+ # return value is an array of hashes.
+ #
lib/sequel/version.rb
--- /tmp/d20260202-1692-qd1ndi/sequel-5.100.0/lib/sequel/version.rb 2026-02-02 03:32:52.282074002 +0000
+++ /tmp/d20260202-1692-qd1ndi/sequel-5.101.0/lib/sequel/version.rb 2026-02-02 03:32:52.323074144 +0000
@@ -9 +9 @@
- MINOR = 100
+ MINOR = 101 |
Contributor
gem compare --diff sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb
--- /tmp/20260202-1634-gozefm 2026-02-02 03:32:54.810595658 +0000
+++ /tmp/d20260202-1634-h1ysdb/sequel-5.101.0/lib/sequel/plugins/detect_unnecessary_association_options.rb 2026-02-02 03:32:54.798595726 +0000
@@ -0,0 +1,164 @@
+# frozen-string-literal: true
+
+module Sequel
+ module Plugins
+ # The detect_unnecessary_association_options plugin can detect unnecessary
+ # association options, and either warn or raise if they are detected.
+ # This allows you to find and remove the unnecessary options.
+ # Association options are considered unnecessary if they specify the same
+ # value as Sequel's defaults.
+ #
+ # To detect unnecessary association options, you should load the plugin
+ # into your model base class (e.g. Sequel::Model) before loading your model
+ # classes. Then, after all models have been loaded, you can call the
+ # detect_unnecessary_association_options on each to check for unnecessary
+ # association options. Additionally, if you are calling finalize_associations,
+ # it will automatically check for unnecessary association options.
+ #
+ # A typical usage would be to combine this with the subclasses plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options
+ # Sequel::Model.plugin :subclasses
+ # # load model classes
+ #
+ # # implicitly check all subclasses when freezing descendants
+ # Sequel::Model.freeze_descendants
+ #
+ # # or, if not freezing all descendants
+ # Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
+ #
+ # By default, the plugin warns for every unnecessary association option.
+ # To raise an error instead, you can pass the <tt>action: :raise</tt> option when loading the
+ # plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
+ #
+ # This plugin only detects the most common unnecessary association options, such as:
+ #
+ # * :class (all associations)
+ # * :key and :primary_key (associations without join tables)
+ # * :join_table, :left_key, :right_key, :left_primary_key, :right_primary_key (single join table associations)
+ # * :left_primary_key, :right_primary_key (*_through_many associations)
+ #
+ # Only association types supported by default or supported by a plugin that
+ # ships with Sequel are supported by this plugin. Other association types are
+ # ignored.
+ module DetectUnnecessaryAssociationOptions
+ def self.configure(model, opts={})
+ model.instance_variable_set(:@detect_unnecessary_association_options_action, opts[:action] || :warn)
+ end
+
+ # Raised if the plugin action is to raise and an unnecessary association option
+ # is detected.
+ class UnnecessaryAssociationOption < Sequel::Error
+ end
+
+ module ClassMethods
+ Plugins.inherited_instance_variables(self, :@detect_unnecessary_association_options_action => nil)
+
+ # Implicitly check for unnecessary association options when finalizing associations.
+ def finalize_associations
+ res = super
+ detect_unnecessary_association_options
+ res
+ end
+
+ # Check for unnecessary association options.
+ def detect_unnecessary_association_options
+ @association_reflections.each_value do |ref|
+ meth = "detect_unnecessary_association_options_#{ref[:type]}"
+ # Expected to call private methods.
+ # Ignore unrecognized association types.
+ # External association types can define the appropriate method to
+ # support their own unnecessary association option checks.
+ if respond_to?(meth, true)
+ # All recognized association types need same class check
+ _detect_unnecessary_association_options_class(ref)
+ send(meth, ref)
+ end
+ end
+
+ nil
+ end
+
+ private
+
+ # Action to take if an unnecessary association option is detected.
+ def unnecessary_association_options_detected(ref, key)
+ if @detect_unnecessary_association_options_action == :raise
+ raise UnnecessaryAssociationOption, "#{ref.inspect} :#{key} option unnecessary"
+ else
+ warn "#{ref.inspect} :#{key} option unnecessary"
+ end
+ end
+
+ # Detect unnecessary :class option.
+ def _detect_unnecessary_association_options_class(ref)
+ return unless ref[:orig_class]
+
+ h = {}
+ name = ref[:name]
+ late_binding_class_option(h, ref.returns_array? ? singularize(name) : name)
+
+ begin
+ default_association_class = constantize(h[:class_name])
+ actual_association_class = ref.associated_class
+ rescue NameError
+ # Do not warn. For the default association class to not be a valid
+ # constant is expected. For the actual association class to not be
+ # a valid constant is not expected and a bug in the association, but
+ # the job of this plugin is not to detect invalid options, only
+ # unnecessary options.
+ else
+ if default_association_class.equal?(actual_association_class)
+ unnecessary_association_options_detected(ref, "class")
+ end
+ end
+ end
+
+ # Detect other unnecessary options. An option is considered unnecessary
+ # if the key was submitted as an association option and the value for
+ # the option is the same as the given value.
+ def _detect_unnecessary_association_options_key_value(ref, key, value)
+ if ref[:orig_opts].has_key?(key) && ref[:orig_opts][key] == value
+ unnecessary_association_options_detected(ref, key)
+ end
+ end
+
+ # Same as _detect_unnecessary_association_options_key_value, but calls
+ # the default_* method on the association reflection to get the default value.
+ def _detect_unnecessary_association_options_key(ref, key)
+ _detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}"))
+ end
+
+ def detect_unnecessary_association_options_many_to_one(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_pg_array_to_many detect_unnecessary_association_options_many_to_one
+
+ def detect_unnecessary_association_options_one_to_many(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, primary_key)
+ end
+ alias detect_unnecessary_association_options_one_to_one detect_unnecessary_association_options_one_to_many
+ alias detect_unnecessary_association_options_many_to_pg_array detect_unnecessary_association_options_one_to_many
+
+ def detect_unnecessary_association_options_many_to_many(ref)
+ [:join_table, :left_key, :right_key].each do |key|
+ _detect_unnecessary_association_options_key(ref, key)
+ end
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_one detect_unnecessary_association_options_many_to_many
+
+ def detect_unnecessary_association_options_many_through_many(ref)
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_many detect_unnecessary_association_options_many_through_many
+ end
+ end
+ end
+end
* Changed:
lib/sequel/dataset/actions.rb
--- /tmp/d20260202-1634-h1ysdb/sequel-5.100.0/lib/sequel/dataset/actions.rb 2026-02-02 03:32:54.726596133 +0000
+++ /tmp/d20260202-1634-h1ysdb/sequel-5.101.0/lib/sequel/dataset/actions.rb 2026-02-02 03:32:54.775595856 +0000
@@ -374,0 +375,9 @@
+ # The return value of this method is undefined and should not be used,
+ # except in two cases:
+ #
+ # * When the <tt>return: :primary_key</tt> option is used.
+ # * On PostgreSQL, when the dataset uses RETURNING. In this case, if
+ # a single value is returned per row, the return value is an array
+ # of those values. If multiple values are returned per row, the
+ # return value is an array of hashes.
+ #
lib/sequel/version.rb
--- /tmp/d20260202-1634-h1ysdb/sequel-5.100.0/lib/sequel/version.rb 2026-02-02 03:32:54.761595936 +0000
+++ /tmp/d20260202-1634-h1ysdb/sequel-5.101.0/lib/sequel/version.rb 2026-02-02 03:32:54.808595670 +0000
@@ -9 +9 @@
- MINOR = 100
+ MINOR = 101 |
Contributor
gem compare --diff sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb
--- /tmp/20260202-1530-ui8xrp 2026-02-02 03:32:55.515286432 +0000
+++ /tmp/d20260202-1530-cqh81s/sequel-5.101.0/lib/sequel/plugins/detect_unnecessary_association_options.rb 2026-02-02 03:32:55.504286444 +0000
@@ -0,0 +1,164 @@
+# frozen-string-literal: true
+
+module Sequel
+ module Plugins
+ # The detect_unnecessary_association_options plugin can detect unnecessary
+ # association options, and either warn or raise if they are detected.
+ # This allows you to find and remove the unnecessary options.
+ # Association options are considered unnecessary if they specify the same
+ # value as Sequel's defaults.
+ #
+ # To detect unnecessary association options, you should load the plugin
+ # into your model base class (e.g. Sequel::Model) before loading your model
+ # classes. Then, after all models have been loaded, you can call the
+ # detect_unnecessary_association_options on each to check for unnecessary
+ # association options. Additionally, if you are calling finalize_associations,
+ # it will automatically check for unnecessary association options.
+ #
+ # A typical usage would be to combine this with the subclasses plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options
+ # Sequel::Model.plugin :subclasses
+ # # load model classes
+ #
+ # # implicitly check all subclasses when freezing descendants
+ # Sequel::Model.freeze_descendants
+ #
+ # # or, if not freezing all descendants
+ # Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
+ #
+ # By default, the plugin warns for every unnecessary association option.
+ # To raise an error instead, you can pass the <tt>action: :raise</tt> option when loading the
+ # plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
+ #
+ # This plugin only detects the most common unnecessary association options, such as:
+ #
+ # * :class (all associations)
+ # * :key and :primary_key (associations without join tables)
+ # * :join_table, :left_key, :right_key, :left_primary_key, :right_primary_key (single join table associations)
+ # * :left_primary_key, :right_primary_key (*_through_many associations)
+ #
+ # Only association types supported by default or supported by a plugin that
+ # ships with Sequel are supported by this plugin. Other association types are
+ # ignored.
+ module DetectUnnecessaryAssociationOptions
+ def self.configure(model, opts={})
+ model.instance_variable_set(:@detect_unnecessary_association_options_action, opts[:action] || :warn)
+ end
+
+ # Raised if the plugin action is to raise and an unnecessary association option
+ # is detected.
+ class UnnecessaryAssociationOption < Sequel::Error
+ end
+
+ module ClassMethods
+ Plugins.inherited_instance_variables(self, :@detect_unnecessary_association_options_action => nil)
+
+ # Implicitly check for unnecessary association options when finalizing associations.
+ def finalize_associations
+ res = super
+ detect_unnecessary_association_options
+ res
+ end
+
+ # Check for unnecessary association options.
+ def detect_unnecessary_association_options
+ @association_reflections.each_value do |ref|
+ meth = "detect_unnecessary_association_options_#{ref[:type]}"
+ # Expected to call private methods.
+ # Ignore unrecognized association types.
+ # External association types can define the appropriate method to
+ # support their own unnecessary association option checks.
+ if respond_to?(meth, true)
+ # All recognized association types need same class check
+ _detect_unnecessary_association_options_class(ref)
+ send(meth, ref)
+ end
+ end
+
+ nil
+ end
+
+ private
+
+ # Action to take if an unnecessary association option is detected.
+ def unnecessary_association_options_detected(ref, key)
+ if @detect_unnecessary_association_options_action == :raise
+ raise UnnecessaryAssociationOption, "#{ref.inspect} :#{key} option unnecessary"
+ else
+ warn "#{ref.inspect} :#{key} option unnecessary"
+ end
+ end
+
+ # Detect unnecessary :class option.
+ def _detect_unnecessary_association_options_class(ref)
+ return unless ref[:orig_class]
+
+ h = {}
+ name = ref[:name]
+ late_binding_class_option(h, ref.returns_array? ? singularize(name) : name)
+
+ begin
+ default_association_class = constantize(h[:class_name])
+ actual_association_class = ref.associated_class
+ rescue NameError
+ # Do not warn. For the default association class to not be a valid
+ # constant is expected. For the actual association class to not be
+ # a valid constant is not expected and a bug in the association, but
+ # the job of this plugin is not to detect invalid options, only
+ # unnecessary options.
+ else
+ if default_association_class.equal?(actual_association_class)
+ unnecessary_association_options_detected(ref, "class")
+ end
+ end
+ end
+
+ # Detect other unnecessary options. An option is considered unnecessary
+ # if the key was submitted as an association option and the value for
+ # the option is the same as the given value.
+ def _detect_unnecessary_association_options_key_value(ref, key, value)
+ if ref[:orig_opts].has_key?(key) && ref[:orig_opts][key] == value
+ unnecessary_association_options_detected(ref, key)
+ end
+ end
+
+ # Same as _detect_unnecessary_association_options_key_value, but calls
+ # the default_* method on the association reflection to get the default value.
+ def _detect_unnecessary_association_options_key(ref, key)
+ _detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}"))
+ end
+
+ def detect_unnecessary_association_options_many_to_one(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_pg_array_to_many detect_unnecessary_association_options_many_to_one
+
+ def detect_unnecessary_association_options_one_to_many(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, primary_key)
+ end
+ alias detect_unnecessary_association_options_one_to_one detect_unnecessary_association_options_one_to_many
+ alias detect_unnecessary_association_options_many_to_pg_array detect_unnecessary_association_options_one_to_many
+
+ def detect_unnecessary_association_options_many_to_many(ref)
+ [:join_table, :left_key, :right_key].each do |key|
+ _detect_unnecessary_association_options_key(ref, key)
+ end
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_one detect_unnecessary_association_options_many_to_many
+
+ def detect_unnecessary_association_options_many_through_many(ref)
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_many detect_unnecessary_association_options_many_through_many
+ end
+ end
+ end
+end
* Changed:
lib/sequel/dataset/actions.rb
--- /tmp/d20260202-1530-cqh81s/sequel-5.100.0/lib/sequel/dataset/actions.rb 2026-02-02 03:32:55.430286530 +0000
+++ /tmp/d20260202-1530-cqh81s/sequel-5.101.0/lib/sequel/dataset/actions.rb 2026-02-02 03:32:55.478286475 +0000
@@ -374,0 +375,9 @@
+ # The return value of this method is undefined and should not be used,
+ # except in two cases:
+ #
+ # * When the <tt>return: :primary_key</tt> option is used.
+ # * On PostgreSQL, when the dataset uses RETURNING. In this case, if
+ # a single value is returned per row, the return value is an array
+ # of those values. If multiple values are returned per row, the
+ # return value is an array of hashes.
+ #
lib/sequel/version.rb
--- /tmp/d20260202-1530-cqh81s/sequel-5.100.0/lib/sequel/version.rb 2026-02-02 03:32:55.465286490 +0000
+++ /tmp/d20260202-1530-cqh81s/sequel-5.101.0/lib/sequel/version.rb 2026-02-02 03:32:55.514286433 +0000
@@ -9 +9 @@
- MINOR = 100
+ MINOR = 101 |
Contributor
gem compare sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT version:
5.100.0: 5.100.0
5.101.0: 5.101.0
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb +164/-0
* Changed:
lib/sequel/dataset/actions.rb +9/-0
lib/sequel/version.rb +1/-1 |
1 similar comment
Contributor
gem compare sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT version:
5.100.0: 5.100.0
5.101.0: 5.101.0
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb +164/-0
* Changed:
lib/sequel/dataset/actions.rb +9/-0
lib/sequel/version.rb +1/-1 |
Contributor
gem compare --diff sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb
--- /tmp/20260202-1560-9fttse 2026-02-02 03:33:15.766126994 +0000
+++ /tmp/d20260202-1560-kqbu50/sequel-5.101.0/lib/sequel/plugins/detect_unnecessary_association_options.rb 2026-02-02 03:33:15.755127042 +0000
@@ -0,0 +1,164 @@
+# frozen-string-literal: true
+
+module Sequel
+ module Plugins
+ # The detect_unnecessary_association_options plugin can detect unnecessary
+ # association options, and either warn or raise if they are detected.
+ # This allows you to find and remove the unnecessary options.
+ # Association options are considered unnecessary if they specify the same
+ # value as Sequel's defaults.
+ #
+ # To detect unnecessary association options, you should load the plugin
+ # into your model base class (e.g. Sequel::Model) before loading your model
+ # classes. Then, after all models have been loaded, you can call the
+ # detect_unnecessary_association_options on each to check for unnecessary
+ # association options. Additionally, if you are calling finalize_associations,
+ # it will automatically check for unnecessary association options.
+ #
+ # A typical usage would be to combine this with the subclasses plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options
+ # Sequel::Model.plugin :subclasses
+ # # load model classes
+ #
+ # # implicitly check all subclasses when freezing descendants
+ # Sequel::Model.freeze_descendants
+ #
+ # # or, if not freezing all descendants
+ # Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
+ #
+ # By default, the plugin warns for every unnecessary association option.
+ # To raise an error instead, you can pass the <tt>action: :raise</tt> option when loading the
+ # plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
+ #
+ # This plugin only detects the most common unnecessary association options, such as:
+ #
+ # * :class (all associations)
+ # * :key and :primary_key (associations without join tables)
+ # * :join_table, :left_key, :right_key, :left_primary_key, :right_primary_key (single join table associations)
+ # * :left_primary_key, :right_primary_key (*_through_many associations)
+ #
+ # Only association types supported by default or supported by a plugin that
+ # ships with Sequel are supported by this plugin. Other association types are
+ # ignored.
+ module DetectUnnecessaryAssociationOptions
+ def self.configure(model, opts={})
+ model.instance_variable_set(:@detect_unnecessary_association_options_action, opts[:action] || :warn)
+ end
+
+ # Raised if the plugin action is to raise and an unnecessary association option
+ # is detected.
+ class UnnecessaryAssociationOption < Sequel::Error
+ end
+
+ module ClassMethods
+ Plugins.inherited_instance_variables(self, :@detect_unnecessary_association_options_action => nil)
+
+ # Implicitly check for unnecessary association options when finalizing associations.
+ def finalize_associations
+ res = super
+ detect_unnecessary_association_options
+ res
+ end
+
+ # Check for unnecessary association options.
+ def detect_unnecessary_association_options
+ @association_reflections.each_value do |ref|
+ meth = "detect_unnecessary_association_options_#{ref[:type]}"
+ # Expected to call private methods.
+ # Ignore unrecognized association types.
+ # External association types can define the appropriate method to
+ # support their own unnecessary association option checks.
+ if respond_to?(meth, true)
+ # All recognized association types need same class check
+ _detect_unnecessary_association_options_class(ref)
+ send(meth, ref)
+ end
+ end
+
+ nil
+ end
+
+ private
+
+ # Action to take if an unnecessary association option is detected.
+ def unnecessary_association_options_detected(ref, key)
+ if @detect_unnecessary_association_options_action == :raise
+ raise UnnecessaryAssociationOption, "#{ref.inspect} :#{key} option unnecessary"
+ else
+ warn "#{ref.inspect} :#{key} option unnecessary"
+ end
+ end
+
+ # Detect unnecessary :class option.
+ def _detect_unnecessary_association_options_class(ref)
+ return unless ref[:orig_class]
+
+ h = {}
+ name = ref[:name]
+ late_binding_class_option(h, ref.returns_array? ? singularize(name) : name)
+
+ begin
+ default_association_class = constantize(h[:class_name])
+ actual_association_class = ref.associated_class
+ rescue NameError
+ # Do not warn. For the default association class to not be a valid
+ # constant is expected. For the actual association class to not be
+ # a valid constant is not expected and a bug in the association, but
+ # the job of this plugin is not to detect invalid options, only
+ # unnecessary options.
+ else
+ if default_association_class.equal?(actual_association_class)
+ unnecessary_association_options_detected(ref, "class")
+ end
+ end
+ end
+
+ # Detect other unnecessary options. An option is considered unnecessary
+ # if the key was submitted as an association option and the value for
+ # the option is the same as the given value.
+ def _detect_unnecessary_association_options_key_value(ref, key, value)
+ if ref[:orig_opts].has_key?(key) && ref[:orig_opts][key] == value
+ unnecessary_association_options_detected(ref, key)
+ end
+ end
+
+ # Same as _detect_unnecessary_association_options_key_value, but calls
+ # the default_* method on the association reflection to get the default value.
+ def _detect_unnecessary_association_options_key(ref, key)
+ _detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}"))
+ end
+
+ def detect_unnecessary_association_options_many_to_one(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_pg_array_to_many detect_unnecessary_association_options_many_to_one
+
+ def detect_unnecessary_association_options_one_to_many(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, primary_key)
+ end
+ alias detect_unnecessary_association_options_one_to_one detect_unnecessary_association_options_one_to_many
+ alias detect_unnecessary_association_options_many_to_pg_array detect_unnecessary_association_options_one_to_many
+
+ def detect_unnecessary_association_options_many_to_many(ref)
+ [:join_table, :left_key, :right_key].each do |key|
+ _detect_unnecessary_association_options_key(ref, key)
+ end
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_one detect_unnecessary_association_options_many_to_many
+
+ def detect_unnecessary_association_options_many_through_many(ref)
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_many detect_unnecessary_association_options_many_through_many
+ end
+ end
+ end
+end
* Changed:
lib/sequel/dataset/actions.rb
--- /tmp/d20260202-1560-kqbu50/sequel-5.100.0/lib/sequel/dataset/actions.rb 2026-02-02 03:33:15.656127471 +0000
+++ /tmp/d20260202-1560-kqbu50/sequel-5.101.0/lib/sequel/dataset/actions.rb 2026-02-02 03:33:15.717127206 +0000
@@ -374,0 +375,9 @@
+ # The return value of this method is undefined and should not be used,
+ # except in two cases:
+ #
+ # * When the <tt>return: :primary_key</tt> option is used.
+ # * On PostgreSQL, when the dataset uses RETURNING. In this case, if
+ # a single value is returned per row, the return value is an array
+ # of those values. If multiple values are returned per row, the
+ # return value is an array of hashes.
+ #
lib/sequel/version.rb
--- /tmp/d20260202-1560-kqbu50/sequel-5.100.0/lib/sequel/version.rb 2026-02-02 03:33:15.697127293 +0000
+++ /tmp/d20260202-1560-kqbu50/sequel-5.101.0/lib/sequel/version.rb 2026-02-02 03:33:15.766126994 +0000
@@ -9 +9 @@
- MINOR = 100
+ MINOR = 101 |
Contributor
gem compare --diff sequel 5.100.0 5.101.0Compared versions: ["5.100.0", "5.101.0"]
DIFFERENT files:
5.100.0->5.101.0:
* Added:
lib/sequel/plugins/detect_unnecessary_association_options.rb
--- /tmp/20260202-1588-ocncn6 2026-02-02 03:33:19.432251183 +0000
+++ /tmp/d20260202-1588-smsbzz/sequel-5.101.0/lib/sequel/plugins/detect_unnecessary_association_options.rb 2026-02-02 03:33:19.415251193 +0000
@@ -0,0 +1,164 @@
+# frozen-string-literal: true
+
+module Sequel
+ module Plugins
+ # The detect_unnecessary_association_options plugin can detect unnecessary
+ # association options, and either warn or raise if they are detected.
+ # This allows you to find and remove the unnecessary options.
+ # Association options are considered unnecessary if they specify the same
+ # value as Sequel's defaults.
+ #
+ # To detect unnecessary association options, you should load the plugin
+ # into your model base class (e.g. Sequel::Model) before loading your model
+ # classes. Then, after all models have been loaded, you can call the
+ # detect_unnecessary_association_options on each to check for unnecessary
+ # association options. Additionally, if you are calling finalize_associations,
+ # it will automatically check for unnecessary association options.
+ #
+ # A typical usage would be to combine this with the subclasses plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options
+ # Sequel::Model.plugin :subclasses
+ # # load model classes
+ #
+ # # implicitly check all subclasses when freezing descendants
+ # Sequel::Model.freeze_descendants
+ #
+ # # or, if not freezing all descendants
+ # Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
+ #
+ # By default, the plugin warns for every unnecessary association option.
+ # To raise an error instead, you can pass the <tt>action: :raise</tt> option when loading the
+ # plugin:
+ #
+ # Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
+ #
+ # This plugin only detects the most common unnecessary association options, such as:
+ #
+ # * :class (all associations)
+ # * :key and :primary_key (associations without join tables)
+ # * :join_table, :left_key, :right_key, :left_primary_key, :right_primary_key (single join table associations)
+ # * :left_primary_key, :right_primary_key (*_through_many associations)
+ #
+ # Only association types supported by default or supported by a plugin that
+ # ships with Sequel are supported by this plugin. Other association types are
+ # ignored.
+ module DetectUnnecessaryAssociationOptions
+ def self.configure(model, opts={})
+ model.instance_variable_set(:@detect_unnecessary_association_options_action, opts[:action] || :warn)
+ end
+
+ # Raised if the plugin action is to raise and an unnecessary association option
+ # is detected.
+ class UnnecessaryAssociationOption < Sequel::Error
+ end
+
+ module ClassMethods
+ Plugins.inherited_instance_variables(self, :@detect_unnecessary_association_options_action => nil)
+
+ # Implicitly check for unnecessary association options when finalizing associations.
+ def finalize_associations
+ res = super
+ detect_unnecessary_association_options
+ res
+ end
+
+ # Check for unnecessary association options.
+ def detect_unnecessary_association_options
+ @association_reflections.each_value do |ref|
+ meth = "detect_unnecessary_association_options_#{ref[:type]}"
+ # Expected to call private methods.
+ # Ignore unrecognized association types.
+ # External association types can define the appropriate method to
+ # support their own unnecessary association option checks.
+ if respond_to?(meth, true)
+ # All recognized association types need same class check
+ _detect_unnecessary_association_options_class(ref)
+ send(meth, ref)
+ end
+ end
+
+ nil
+ end
+
+ private
+
+ # Action to take if an unnecessary association option is detected.
+ def unnecessary_association_options_detected(ref, key)
+ if @detect_unnecessary_association_options_action == :raise
+ raise UnnecessaryAssociationOption, "#{ref.inspect} :#{key} option unnecessary"
+ else
+ warn "#{ref.inspect} :#{key} option unnecessary"
+ end
+ end
+
+ # Detect unnecessary :class option.
+ def _detect_unnecessary_association_options_class(ref)
+ return unless ref[:orig_class]
+
+ h = {}
+ name = ref[:name]
+ late_binding_class_option(h, ref.returns_array? ? singularize(name) : name)
+
+ begin
+ default_association_class = constantize(h[:class_name])
+ actual_association_class = ref.associated_class
+ rescue NameError
+ # Do not warn. For the default association class to not be a valid
+ # constant is expected. For the actual association class to not be
+ # a valid constant is not expected and a bug in the association, but
+ # the job of this plugin is not to detect invalid options, only
+ # unnecessary options.
+ else
+ if default_association_class.equal?(actual_association_class)
+ unnecessary_association_options_detected(ref, "class")
+ end
+ end
+ end
+
+ # Detect other unnecessary options. An option is considered unnecessary
+ # if the key was submitted as an association option and the value for
+ # the option is the same as the given value.
+ def _detect_unnecessary_association_options_key_value(ref, key, value)
+ if ref[:orig_opts].has_key?(key) && ref[:orig_opts][key] == value
+ unnecessary_association_options_detected(ref, key)
+ end
+ end
+
+ # Same as _detect_unnecessary_association_options_key_value, but calls
+ # the default_* method on the association reflection to get the default value.
+ def _detect_unnecessary_association_options_key(ref, key)
+ _detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}"))
+ end
+
+ def detect_unnecessary_association_options_many_to_one(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_pg_array_to_many detect_unnecessary_association_options_many_to_one
+
+ def detect_unnecessary_association_options_one_to_many(ref)
+ _detect_unnecessary_association_options_key(ref, :key)
+ _detect_unnecessary_association_options_key_value(ref, :primary_key, primary_key)
+ end
+ alias detect_unnecessary_association_options_one_to_one detect_unnecessary_association_options_one_to_many
+ alias detect_unnecessary_association_options_many_to_pg_array detect_unnecessary_association_options_one_to_many
+
+ def detect_unnecessary_association_options_many_to_many(ref)
+ [:join_table, :left_key, :right_key].each do |key|
+ _detect_unnecessary_association_options_key(ref, key)
+ end
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_one detect_unnecessary_association_options_many_to_many
+
+ def detect_unnecessary_association_options_many_through_many(ref)
+ _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key)
+ _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key)
+ end
+ alias detect_unnecessary_association_options_one_through_many detect_unnecessary_association_options_many_through_many
+ end
+ end
+ end
+end
* Changed:
lib/sequel/dataset/actions.rb
--- /tmp/d20260202-1588-smsbzz/sequel-5.100.0/lib/sequel/dataset/actions.rb 2026-02-02 03:33:19.334251240 +0000
+++ /tmp/d20260202-1588-smsbzz/sequel-5.101.0/lib/sequel/dataset/actions.rb 2026-02-02 03:33:19.387251209 +0000
@@ -374,0 +375,9 @@
+ # The return value of this method is undefined and should not be used,
+ # except in two cases:
+ #
+ # * When the <tt>return: :primary_key</tt> option is used.
+ # * On PostgreSQL, when the dataset uses RETURNING. In this case, if
+ # a single value is returned per row, the return value is an array
+ # of those values. If multiple values are returned per row, the
+ # return value is an array of hashes.
+ #
lib/sequel/version.rb
--- /tmp/d20260202-1588-smsbzz/sequel-5.100.0/lib/sequel/version.rb 2026-02-02 03:33:19.372251218 +0000
+++ /tmp/d20260202-1588-smsbzz/sequel-5.101.0/lib/sequel/version.rb 2026-02-02 03:33:19.431251184 +0000
@@ -9 +9 @@
- MINOR = 100
+ MINOR = 101 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bumps sequel from 5.100.0 to 5.101.0.
Changelog
Sourced from sequel's changelog.
Commits
e042ab7Bump version to 5.101.08ea9e45Work around regression in MySQL 9.6.0 in eager loader test4293be3Document #import return values (Fixes #2347)5ebcb7aAdd detect_unnecessary_association_options plugin to warn/raise for unnecessa...Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebasewill rebase this PR@dependabot recreatewill recreate this PR, overwriting any edits that have been made to it@dependabot mergewill merge this PR after your CI passes on it@dependabot squash and mergewill squash and merge this PR after your CI passes on it@dependabot cancel mergewill cancel a previously requested merge and block automerging@dependabot reopenwill reopen this PR if it is closed@dependabot closewill close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot show <dependency name> ignore conditionswill show all of the ignore conditions of the specified dependency@dependabot ignore this major versionwill close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor versionwill close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependencywill close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)