Commit Graph

79596 Commits

Author SHA1 Message Date
Kasper Timm Hansen
d24b9e3f3a
Merge pull request #41714 from p8/fix-dirty-autosave-on-has-many
Prevent double save of cyclic associations
2021-03-23 22:59:00 +01:00
Petrik
a1a5d37749 Prevent double save of cyclic associations
Autosave will double save records for some cyclic associations.
For example a child record with a parent association.
If save is called on the child before the parent has been saved,
the child will be saved twice.
The double save of the child will clear the mutation tracker on
the child record resulting in an incorrect dirty state.

```
    # pirate has_one ship
    ship = Ship.new(name: "Nights Dirty Lightning")
    pirate = ship.build_pirate(catchphrase: "Aye")
    ship.save!
    ship.previous_changes # => returns {} but this should contain the changes.
```

When saving ship the following happens:
1. the `before_save` callbacks of the ship are called
2. the callbacks call `autosave_associated_records_for_pirate`
3. `autosave_associated_records_for_pirate` saves the pirate
4. the `after_save` callbacks of the pirate are called
5. the callbacks call `autosave_associated_records_for_ship`
6. `autosave_associated_records_for_ship` saves the ship
7. the ship is saved again by the original save

`autosave_associated_records_for_ship` saves the ship because the ship
association is set by inverse_of in a `has_one` on the pirate. This does
not happen with a `has_many` by default because the inverse is not set.
If setting the inverse on the `has_many` the problem occurs as well.

----------------------------

This commit adds a @saving state which tracks if a record is currently being saved.
If @saving is set to true, the record won't be saved by the autosave callbacks.

With this commit the following happens when saving a ship:
1. @saving is set to true
2. the `before_save` callbacks of the ship are called
3. the callbacks call `autosave_associated_records_for_pirate`
5. `autosave_associated_records_for_pirate` saves the pirate
6. the `after_save` callbacks of the pirate are called
6. `autosave_associated_records_for_ship` skip saving the ship
8. the ship is saved.
9. @saving is set to false

One disadvantage of this approach is the following...
While the child is no longer saved in the autosave, similar children
could be autosaved. This will result in unexpected order when creating
new records, as similar children will be commited first.
2021-03-23 22:01:27 +01:00
Eugene Kenny
8306b9614c
Merge pull request #41744 from AlexB52/fix-join-query-sql
[ci skip] Fix SQL result of `Book.joins(reviews: :customer)` query example
2021-03-23 20:32:16 +00:00
Alexandre Barret
7a0cb3d239 Fix SQL result of Book.joins(reviews: :customer) query example 2021-03-24 09:09:11 +13:00
Eileen M. Uchitelle
ad9e52066c
Merge pull request #41684 from ricardotk002/disable-parallel-testing
Disable parallel testing when running individual files
2021-03-23 09:06:57 -04:00
Eileen M. Uchitelle
f568be4c8c
Merge pull request #41713 from henrik/lookup
'lookup' -> 'look up' in dummy webpacker.ymls
2021-03-23 09:05:37 -04:00
Ryuta Kamizono
e287eed77a
Merge pull request #41737 from Shopify/fork-tracker-delegation
Use triple-dot delegation in ForkTracker
2021-03-23 20:05:34 +09:00
Jean Boussier
a40fca290d Use triple-dot delegation in ForkTracker 2021-03-23 08:52:29 +01:00
Ryuta Kamizono
2f29b643f7 Merge pull request #41736 from lairtonmendes/6-1-stable
remove unecessary sufix

[ci skip]
2021-03-23 11:01:10 +09:00
Ryuta Kamizono
f8dba9e64a Fix WhereClause#extract_attributes to work it with a string where clause
Fixes #41696.
2021-03-23 10:47:10 +09:00
Ryuta Kamizono
19fd39b672 to_yaml requires require "yaml"
https://buildkite.com/rails/rails/builds/75966#6b542bd0-82ce-4463-badf-7a68af7d3208/1055-1977
2021-03-23 08:51:39 +09:00
Ryuta Kamizono
3e71243b10 Parsing type="yaml" node requires require "yaml" 2021-03-23 08:45:46 +09:00
Ryuta Kamizono
d7f5f4f97f Fix test_from_trusted_xml_allows_symbol_and_yaml_types failure
Caused by #41712.

https://buildkite.com/rails/rails/builds/75962#984c08aa-f57f-4f1c-ab31-7674fac12bbe/975-1397
2021-03-23 08:29:09 +09:00
Ryuta Kamizono
ee0420ffcc
Merge pull request #41731 from henrik/typo-rel
Fix typo in 6.1 release notes

[ci skip]
2021-03-23 08:24:29 +09:00
Rafael França
3262492bed
Merge pull request #41733 from henrik/consistent-quotes
More consistent quotes in template files
2021-03-22 18:22:21 -04:00
Rafael Mendonça França
741099e995
Really make OrderedHash private to the framework
Related to 0dd76540327be58999b0cb7584277724e60486d3.
2021-03-22 22:13:23 +00:00
Henrik Nyh
c13fee85ba More consistent quotes in template files 2021-03-22 22:07:27 +00:00
Rafael França
d86475af51
Merge pull request #41734 from rails/rm-fix-preload-extending
Batch queries that are the same but are using different extension
2021-03-22 18:03:20 -04:00
Rafael Mendonça França
57514ecf6c
Remove non-project specific entry from gitignore 2021-03-22 22:02:00 +00:00
Rafael França
84c9941642
Merge pull request #41080 from ankurp/standardrb-fixes
Update template files to follow the standard gem code formatter recommendations
2021-03-22 18:01:35 -04:00
Rafael Mendonça França
21e0c20667
Batch queries that are the same but are using different extension
If an association scope would generate the same query but have different
values for `extending`, `skip_query_cache` or `strict_loading` we should
consider them the same for the purpose of generating the preload
batches.
2021-03-22 21:51:18 +00:00
Henrik Nyh
959266998f Fix typo in 6.1 release notes 2021-03-22 21:15:17 +00:00
Ryuta Kamizono
e8fb1ac705
Merge pull request #41729 from kamipo/fix_test_polymorphic_assignment_foreign_key_type_string
Fix the test case for #14855 to catch a future regression correctly
2021-03-23 05:11:04 +09:00
Ryuta Kamizono
eb6a43a798 Fix the test case for #14855 to catch a future regression correctly
I've found the test doesn't catch a future regression since it doesn't
assert the result of the preload.

Also, add extra assertions to assert the difference of the value type.
2021-03-23 04:55:33 +09:00
Rafael Mendonça França
6388e300e5
Revert "Fix schema for members"
This reverts commit 8da6ba9cae21beae1ee3c379db7b7113d2731c9b.

The type is not standard to make sure preload work when the types don't
match.

See #14855.
2021-03-22 19:45:09 +00:00
Ryuta Kamizono
1ef30c19b5
Merge pull request #41712 from okuramasafumi/remove-ordered-hash
Remove requires and references to OrderedHash
2021-03-22 22:01:26 +09:00
OKURA Masafumi
0dd7654032 Remove some references to OrderedHash
OrderedHash is deprecated but there are some requires and references
to OrderedHash, which might be confusing.
As described in
https://github.com/rails/rails/issues/22681#issuecomment-166059717
OrderedHash is internal only so references in the docs should be
removed.
2021-03-22 21:14:32 +09:00
Ryuta Kamizono
7c67b94986 Make infinity handling symmetrical in cast and deserialize
Related: #41716, 30391e9ddba745d6bdc0b23f526ecf432dfe6adf.
2021-03-22 15:47:20 +09:00
Ryuta Kamizono
bbac68d428
Merge pull request #41716 from shunichi/fix-postgresql-infinity-datetime
Fix Float::INFINITY assignment to datetime attributes
2021-03-22 15:16:07 +09:00
Shunichi Ikegami
800d6bd1df Fix Float::INFINITY assignment to datetime attributes
After assigning string "infinity" to datetime attribute with postgresql adapter, reading it back gets Float::INFINITY.
But assigning Float::INFINITY to datetime attribute results in getting nil value when ActiveRecord::Base.time_zone_aware_attributes is true.
This is due to TimeZoneConverter not handling Float::INFINITY appropriately.
2021-03-22 13:56:06 +09:00
Ryuta Kamizono
ef99e7d509
Merge pull request #41602 from intrip/40550-fix-throw-abort-on-belongs-to-third-level-rollback
Fix rollback of parent destruction with nested dependent:destroy
2021-03-22 13:39:52 +09:00
Ryuta Kamizono
c7a036c2b6 Revert "Passing in a Hash instance as non-kwargs parameters has to be curly braced now"
This reverts commit d2f4541f126001e029078cc48a3a481e23ae3ed9.

It should work without curly braces.

See also: #41198, #41206, 81d90d81d0ee1fc1a649ab705119a71f2d04c8a2.
2021-03-22 11:21:33 +09:00
Ryuta Kamizono
81d90d81d0 Allow both current_page?(url_hash) and current_page?(**url_hash) on Ruby 2.7
Keyword argument warnings are caused by #41206 to allow both
`current_page?(url_hash)` and `current_page?(**url_hash)` on Ruby 3.0.

Unfortunately it is super hard to support that for both Ruby 2.7 and 3.0
with the same method signature.

Closes #41710.
2021-03-22 10:57:45 +09:00
Ryuta Kamizono
8c7883d3fc ✂️ [ci skip] 2021-03-22 04:46:11 +09:00
Henrik Nyh
515108ee03 'lookup' -> 'look up' in dummy webpacker.ymls
Corresponding to this fix: https://github.com/rails/webpacker/pull/2961
2021-03-21 12:36:56 +00:00
Ryuta Kamizono
043184d903 Fix end alignment 2021-03-21 15:46:36 +09:00
Ryuta Kamizono
1dcad65f80
Merge pull request #41707 from okuramasafumi/add-missing-require-to-hash_with_indifferent_access
Add missing require to hash_with_indifferent_access
2021-03-21 15:19:44 +09:00
Jean Boussier
39341de433 Remove useless include_private parameter in define_proxy_call
Since Ruby 2.7 `self.some_private_method` works fine.
So now that Ruby 2.7 is the minimal supported version,
`define_proxy_call` can always prepend `self.`
2021-03-20 14:27:53 -04:00
OKURA Masafumi
8a56380c53
Add documentation to HashWithIndifferentAccess#except
https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html#method-i-except
Currently HashWithIndifferentAccess#except has no documentation.
Since it's behavior is different from Hash#except, so it deserves
its own documentation.
2021-03-20 10:37:13 -04:00
OKURA Masafumi
e4de1ca9b5 Add missing require to hash_with_indifferent_access
When requiring only "active_support/hash_with_indifferent_access",
calling `slice!` method on `HashWithIndifferentAccess` object
causes `NoMethodError`.
This is caused by `slice!` method calls `super` which is defined
in "active_support/core_ext/hash/slice" that' not required by this file.
Adding `require "active_support/core_ext/hash/slice"` to hwia
resolves this issue.

Note: since all tests `require_relative "abstract_unit"` that requires
"active_support/core_ext/hash/slice" eventually, it's pretty hard to
test method behavior without require.
2021-03-20 22:10:38 +09:00
Ryuta Kamizono
a8a1afd455
Merge pull request #41703 from Shopify/tripple-dot
Use `...` argument forwarding instead of ruby2_keywords when possible
2021-03-20 02:38:59 +09:00
James Brooks
b1b0b22f50
Always render attachment partials as HTML with :html format inside trix editor 2021-03-19 13:35:09 -04:00
Máximo Mussini
1598ad5c4b
Ensure modules are preloaded correctly using rel=modulepreload.
Prior to this change, javascript_include_tag was sending a hint using
rel="preload" for all scripts, including those of type="module".

This causes the browser to make a request to preload the script, but
because the rel is incorrect, it won't be able to reuse it.

When passing type="module", it should use rel=modulepreload instead.

[0] developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
[2] developer.mozilla.org/en-US/docs/Web/HTML/Link_types/modulepreload
2021-03-19 13:22:22 -04:00
Ryuta Kamizono
b5c4af7d52
Merge pull request #41068 from ricardotk002/fix-where-in-stmt-logging
Fix binds logging for "WHERE ... IN ..." statements
2021-03-20 01:41:29 +09:00
Jean Boussier
8a3fcad2d2 Use ... argument forwarding instead of ruby2_keywords when possible 2021-03-19 16:53:06 +01:00
Xavier Noria
6d38553b09 Removes the monkey-patch for Marshal.load
Marshal.load autoloads out of the box with Zeitwerk. See

    https://github.com/fxn/zeitwerk/blob/master/test/lib/zeitwerk/test_marshal.rb

for similar coverage.
2021-03-18 22:08:25 +01:00
eileencodes
8da6ba9cae
Fix schema for members
While working on another branch I noticed that this `resource_id` was
set to a string. I ran all the tests for sqlite, mysql, and postgres and
none failed so I think this is an oversight. As far as I can tell this
was supposed to be an integer.
2021-03-18 10:00:08 -04:00
Ricardo Díaz
2327ebfdc6 Disable parallel testing when running individual files
Setting up the parallel workers could be an overhead when running
individual files.

This patch disables that process in case the number of files to run
is less than one.

Results running a sample file:

Before:

```
actionpack $ bin/test test/controller/parameters/accessors_test.rb
Run options: --seed 48261

........................................................................

Finished in 0.211923s, 339.7460 runs/s, 552.0873 assertions/s.
72 runs, 117 assertions, 0 failures, 0 errors, 0 skips
```

After

```
actionpack $ bin/test test/controller/parameters/accessors_test.rb

Run options: --seed 5461

........................................................................

Finished in 0.008411s, 8560.2189 runs/s, 13910.3557 assertions/s.
72 runs, 117 assertions, 0 failures, 0 errors, 0 skips
```
2021-03-18 02:06:42 -05:00
eileencodes
5e300f1121
Fix test name
I copied the previous test and forgot to remain it. This commit fixes
the test name.
2021-03-17 09:19:55 -04:00
Ryuta Kamizono
6ab3191ed6
Merge pull request #41675 from kamipo/dont_use_cast_in_unboundable
Don't use `type.cast(value)` to emulate unchecked serialized value in `unboundable?`
2021-03-17 20:21:34 +09:00