activerecord 5.0.3 → 5.0.4.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2aa37fd1fc57e36d5f14ee9009cf6ba7ec6b601
4
- data.tar.gz: c974b336ea71a782c1381d480c0ef2687dfc32c3
3
+ metadata.gz: 2efd7fbd7510c25737c23d07f6a3a21ae2212799
4
+ data.tar.gz: 4feae8265a13e0ceadc555f7782a060496ce8a78
5
5
  SHA512:
6
- metadata.gz: f27b1ef2da04f68ac793b7039dc8ff8e0c78d8cf8db60d0b554f00174882b025d41dde0a4ad1a86ad5dad95c9facd826852b398c666968965cb54154d7f27cc6
7
- data.tar.gz: e792934d6d1a39b07fef4cbff53969729f292edab3e23ea33231ba087b23d7e8a3eed648135fa45fc4e023dc8c217e7260753f3d69defeca3ecf0e21cabe804c
6
+ metadata.gz: 6bb37c2e141d44d05513ab357d30a31f970d0de3c3a989706e3b2ba314acc236f30bd15122c0e69353e447fe9de4ddb176a9c20510c87b26bb0c4a1637dcee38
7
+ data.tar.gz: a5226dfdb2cdae166477a295b1d0d95e22054070155384c4c6daad65780687d5ba6b1fb6167c87359bcc63c03a7ba184b54976c7b44cca783a2febb8a47e5b7b
@@ -1,3 +1,20 @@
1
+ ## Rails 5.0.4.rc1 (June 14, 2017) ##
2
+
3
+ * Restore previous behavior of collection proxies: their values can have
4
+ methods stubbed, and they respect extension modules applied by a default
5
+ scope.
6
+
7
+ *Ryuta Kamizono*
8
+
9
+ * Loading model schema from database is now thread-safe.
10
+
11
+ Fixes #28589.
12
+
13
+ *Vikrant Chaudhary*, *David Abdemoulaie*
14
+
15
+
16
+ ## Rails 5.0.3 (May 12, 2017) ##
17
+
1
18
  * Check whether `Rails.application` defined before calling it
2
19
 
3
20
  In #27674 we changed the migration generator to generate migrations at the
@@ -124,6 +124,16 @@ module ActiveRecord
124
124
  AssociationRelation.create(klass, klass.arel_table, klass.predicate_builder, self).merge!(klass.all)
125
125
  end
126
126
 
127
+ def extensions
128
+ extensions = klass.default_extensions | reflection.extensions
129
+
130
+ if scope = reflection.scope
131
+ extensions |= klass.unscoped.instance_exec(owner, &scope).extensions
132
+ end
133
+
134
+ extensions
135
+ end
136
+
127
137
  # Loads the \target if needed and returns it.
128
138
  #
129
139
  # This method is abstract in the sense that it relies on +find_target+,
@@ -24,7 +24,7 @@ module ActiveRecord
24
24
  alias_tracker = AliasTracker.create connection, association.klass.table_name, klass.type_caster
25
25
  chain_head, chain_tail = get_chain(reflection, association, alias_tracker)
26
26
 
27
- scope.extending! Array(reflection.options[:extend])
27
+ scope.extending! reflection.extensions
28
28
  add_constraints(scope, owner, klass, reflection, chain_head, chain_tail)
29
29
  end
30
30
 
@@ -39,7 +39,8 @@ module ActiveRecord
39
39
  reload
40
40
  end
41
41
 
42
- CollectionProxy.create(klass, self)
42
+ @proxy ||= CollectionProxy.create(klass, self)
43
+ @proxy.reset_scope
43
44
  end
44
45
 
45
46
  # Implements the writer method, e.g. foo.items= for Foo.has_many :items
@@ -31,6 +31,9 @@ module ActiveRecord
31
31
  def initialize(klass, association) #:nodoc:
32
32
  @association = association
33
33
  super klass, klass.arel_table, klass.predicate_builder
34
+
35
+ extensions = association.extensions
36
+ extend(*extensions) if extensions.any?
34
37
  end
35
38
 
36
39
  def target
@@ -1034,9 +1037,8 @@ module ActiveRecord
1034
1037
  # person.pets(true) # fetches pets from the database
1035
1038
  # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
1036
1039
  def reload
1037
- @scope = nil
1038
1040
  proxy_association.reload
1039
- self
1041
+ reset_scope
1040
1042
  end
1041
1043
 
1042
1044
  # Unloads the association. Returns +self+.
@@ -1056,9 +1058,13 @@ module ActiveRecord
1056
1058
  # person.pets # fetches pets from the database
1057
1059
  # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
1058
1060
  def reset
1059
- @scope = nil
1060
1061
  proxy_association.reset
1061
1062
  proxy_association.reset_scope
1063
+ reset_scope
1064
+ end
1065
+
1066
+ def reset_scope # :nodoc:
1067
+ @scope = nil
1062
1068
  self
1063
1069
  end
1064
1070
 
@@ -1071,36 +1077,15 @@ module ActiveRecord
1071
1077
 
1072
1078
  delegate(*delegate_methods, to: :scope)
1073
1079
 
1074
- module DelegateExtending # :nodoc:
1075
- private
1076
- def method_missing(method, *args, &block)
1077
- extending_values = association_scope.extending_values
1078
- if extending_values.any? && (extending_values - self.class.included_modules).any?
1079
- self.class.include(*extending_values)
1080
- public_send(method, *args, &block)
1081
- else
1082
- super
1083
- end
1084
- end
1085
- end
1086
-
1087
1080
  private
1088
1081
 
1089
1082
  def null_scope?
1090
1083
  @association.null_scope?
1091
1084
  end
1092
1085
 
1093
- def association_scope
1094
- @association.association_scope
1095
- end
1096
-
1097
1086
  def exec_queries
1098
1087
  load_target
1099
1088
  end
1100
-
1101
- def respond_to_missing?(method, _)
1102
- association_scope.respond_to?(method) || super
1103
- end
1104
1089
  end
1105
1090
  end
1106
1091
  end
@@ -112,7 +112,7 @@ module ActiveRecord
112
112
  end
113
113
 
114
114
  def polymorphic_options
115
- as_options(polymorphic)
115
+ as_options(polymorphic).merge(null: options[:null])
116
116
  end
117
117
 
118
118
  def index_options
@@ -375,9 +375,17 @@ module ActiveRecord
375
375
 
376
376
  if pk && sequence
377
377
  quoted_sequence = quote_table_name(sequence)
378
+ max_pk = select_value("select MAX(#{quote_column_name pk}) from #{quote_table_name(table)}")
379
+ if max_pk.nil?
380
+ if postgresql_version >= 100000
381
+ minvalue = select_value("SELECT seqmin from pg_sequence where seqrelid = '#{quoted_sequence}'::regclass")
382
+ else
383
+ minvalue = select_value("SELECT min_value FROM #{quoted_sequence}")
384
+ end
385
+ end
378
386
 
379
- select_value(<<-end_sql, 'SCHEMA')
380
- SELECT setval('#{quoted_sequence}', (SELECT COALESCE(MAX(#{quote_column_name pk})+(SELECT increment_by FROM #{quoted_sequence}), (SELECT min_value FROM #{quoted_sequence})) FROM #{quote_table_name(table)}), false)
387
+ select_value(<<-end_sql, "SCHEMA")
388
+ SELECT setval('#{quoted_sequence}', #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false})
381
389
  end_sql
382
390
  end
383
391
  end
@@ -7,8 +7,8 @@ module ActiveRecord
7
7
  module VERSION
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
- TINY = 3
11
- PRE = nil
10
+ TINY = 4
11
+ PRE = "rc1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,3 +1,5 @@
1
+ require "monitor"
2
+
1
3
  module ActiveRecord
2
4
  module ModelSchema
3
5
  extend ActiveSupport::Concern
@@ -152,6 +154,8 @@ module ActiveRecord
152
154
  self.inheritance_column = 'type'
153
155
 
154
156
  delegate :type_for_attribute, to: :class
157
+
158
+ initialize_load_schema_monitor
155
159
  end
156
160
 
157
161
  # Derives the join table name for +first_table+ and +second_table+. The
@@ -426,15 +430,31 @@ module ActiveRecord
426
430
  initialize_find_by_cache
427
431
  end
428
432
 
433
+ protected
434
+
435
+ def initialize_load_schema_monitor
436
+ @load_schema_monitor = Monitor.new
437
+ end
438
+
429
439
  private
430
440
 
441
+ def inherited(child_class)
442
+ super
443
+ child_class.initialize_load_schema_monitor
444
+ end
445
+
431
446
  def schema_loaded?
432
- defined?(@columns_hash) && @columns_hash
447
+ defined?(@schema_loaded) && @schema_loaded
433
448
  end
434
449
 
435
450
  def load_schema
436
- unless schema_loaded?
451
+ return if schema_loaded?
452
+ @load_schema_monitor.synchronize do
453
+ return if defined?(@columns_hash) && @columns_hash
454
+
437
455
  load_schema!
456
+
457
+ @schema_loaded = true
438
458
  end
439
459
  end
440
460
 
@@ -462,6 +482,7 @@ module ActiveRecord
462
482
  @attributes_builder = nil
463
483
  @columns = nil
464
484
  @columns_hash = nil
485
+ @schema_loaded = false
465
486
  @attribute_names = nil
466
487
  direct_descendants.each do |descendant|
467
488
  descendant.send(:reload_schema_from_cache)
@@ -527,6 +527,10 @@ module ActiveRecord
527
527
  seed + [self]
528
528
  end
529
529
 
530
+ def extensions
531
+ Array(options[:extend])
532
+ end
533
+
530
534
  protected
531
535
 
532
536
  def actual_source_reflection # FIXME: this is a horrible name
@@ -30,11 +30,11 @@ module ActiveRecord
30
30
  # end
31
31
  #
32
32
  # ==== Options
33
- # * <tt>:batch_size</tt> - Specifies the size of the batch. Default to 1000.
33
+ # * <tt>:batch_size</tt> - Specifies the size of the batch. Defaults to 1000.
34
34
  # * <tt>:start</tt> - Specifies the primary key value to start from, inclusive of the value.
35
35
  # * <tt>:finish</tt> - Specifies the primary key value to end at, inclusive of the value.
36
36
  # * <tt>:error_on_ignore</tt> - Overrides the application config to specify if an error should be raised when
37
- # the order and limit have to be ignored due to batching.
37
+ # the order and limit have to be ignored due to batching.
38
38
  #
39
39
  # This is especially useful if you want multiple workers dealing with
40
40
  # the same processing queue. You can make worker 1 handle all the records
@@ -85,11 +85,11 @@ module ActiveRecord
85
85
  # To be yielded each record one by one, use #find_each instead.
86
86
  #
87
87
  # ==== Options
88
- # * <tt>:batch_size</tt> - Specifies the size of the batch. Default to 1000.
88
+ # * <tt>:batch_size</tt> - Specifies the size of the batch. Defaults to 1000.
89
89
  # * <tt>:start</tt> - Specifies the primary key value to start from, inclusive of the value.
90
90
  # * <tt>:finish</tt> - Specifies the primary key value to end at, inclusive of the value.
91
91
  # * <tt>:error_on_ignore</tt> - Overrides the application config to specify if an error should be raised when
92
- # the order and limit have to be ignored due to batching.
92
+ # the order and limit have to be ignored due to batching.
93
93
  #
94
94
  # This is especially useful if you want multiple workers dealing with
95
95
  # the same processing queue. You can make worker 1 handle all the records
@@ -132,9 +132,9 @@ module ActiveRecord
132
132
  # If you do not provide a block to #in_batches, it will return a
133
133
  # BatchEnumerator which is enumerable.
134
134
  #
135
- # Person.in_batches.with_index do |relation, batch_index|
135
+ # Person.in_batches.each_with_index do |relation, batch_index|
136
136
  # puts "Processing relation ##{batch_index}"
137
- # relation.each { |relation| relation.delete_all }
137
+ # relation.delete_all
138
138
  # end
139
139
  #
140
140
  # Examples of calling methods on the returned BatchEnumerator object:
@@ -144,12 +144,12 @@ module ActiveRecord
144
144
  # Person.in_batches.each_record(&:party_all_night!)
145
145
  #
146
146
  # ==== Options
147
- # * <tt>:of</tt> - Specifies the size of the batch. Default to 1000.
148
- # * <tt>:load</tt> - Specifies if the relation should be loaded. Default to false.
147
+ # * <tt>:of</tt> - Specifies the size of the batch. Defaults to 1000.
148
+ # * <tt>:load</tt> - Specifies if the relation should be loaded. Defaults to false.
149
149
  # * <tt>:start</tt> - Specifies the primary key value to start from, inclusive of the value.
150
150
  # * <tt>:finish</tt> - Specifies the primary key value to end at, inclusive of the value.
151
151
  # * <tt>:error_on_ignore</tt> - Overrides the application config to specify if an error should be raised when
152
- # the order and limit have to be ignored due to batching.
152
+ # the order and limit have to be ignored due to batching.
153
153
  #
154
154
  # This is especially useful if you want to work with the
155
155
  # ActiveRecord::Relation object instead of the array of records, or if
@@ -176,7 +176,7 @@ module ActiveRecord
176
176
  #
177
177
  # NOTE: It's not possible to set the order. That is automatically set to
178
178
  # ascending on the primary key ("id ASC") to make the batch ordering
179
- # consistent. Therefore the primary key must be orderable, e.g an integer
179
+ # consistent. Therefore the primary key must be orderable, e.g. an integer
180
180
  # or a string.
181
181
  #
182
182
  # NOTE: You can't set the limit either, that's used to control the batch
@@ -24,8 +24,6 @@ module ActiveRecord
24
24
 
25
25
  def inherited(child_class)
26
26
  child_class.initialize_relation_delegate_cache
27
- delegate = child_class.relation_delegate_class(ActiveRecord::Associations::CollectionProxy)
28
- delegate.include ActiveRecord::Associations::CollectionProxy::DelegateExtending
29
27
  super
30
28
  end
31
29
  end
@@ -110,7 +110,11 @@ module ActiveRecord
110
110
 
111
111
  if self.default_scope_override
112
112
  # The user has defined their own default scope method, so call that
113
- evaluate_default_scope { default_scope }
113
+ evaluate_default_scope do
114
+ if scope = default_scope
115
+ (base_rel ||= relation).merge(scope)
116
+ end
117
+ end
114
118
  elsif default_scopes.any?
115
119
  base_rel ||= relation
116
120
  evaluate_default_scope do
@@ -30,12 +30,15 @@ module ActiveRecord
30
30
  end
31
31
 
32
32
  def default_scoped # :nodoc:
33
- scope = build_default_scope
33
+ scope = relation
34
+ build_default_scope(scope) || scope
35
+ end
34
36
 
35
- if scope
36
- relation.spawn.merge!(scope)
37
+ def default_extensions # :nodoc:
38
+ if scope = current_scope || build_default_scope
39
+ scope.extensions
37
40
  else
38
- relation
41
+ []
39
42
  end
40
43
  end
41
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3
4
+ version: 5.0.4.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-12 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.3
19
+ version: 5.0.4.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.3
26
+ version: 5.0.4.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.3
33
+ version: 5.0.4.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 5.0.3
40
+ version: 5.0.4.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -323,14 +323,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
323
323
  version: 2.2.2
324
324
  required_rubygems_version: !ruby/object:Gem::Requirement
325
325
  requirements:
326
- - - ">="
326
+ - - ">"
327
327
  - !ruby/object:Gem::Version
328
- version: '0'
328
+ version: 1.3.1
329
329
  requirements: []
330
330
  rubyforge_project:
331
- rubygems_version: 2.6.10
331
+ rubygems_version: 2.6.12
332
332
  signing_key:
333
333
  specification_version: 4
334
334
  summary: Object-relational mapper framework (part of Rails).
335
335
  test_files: []
336
- has_rdoc: