Commit Graph

79609 Commits

Author SHA1 Message Date
Ryuta Kamizono
2eb5458978 Rename internal @saving state to @_saving
Usually we add `_` prefix for newly added short term living (used)
internal state (e.g. ae02898, d1107f4, dcb8259), and also `@saving`
might be already used in users' code.
2021-03-25 03:08:06 +09:00
Rafael França
7702ce8243
Merge pull request #40789 from csutter/deprecate-remote-ip-single-value
Deprecate assigning single `trusted_proxies` value
2021-03-24 02:27:57 -04:00
Rafael França
7a0e5afdea
Merge pull request #41745 from dylanahsmith/ar-class-inspection-filter
Move @inspection_filter to the class to avoid marshal dumping it
2021-03-24 01:05:41 -04:00
Cory Gwin
96b3d5a026
Document Destroy Async (#41680)
* Document Destroy Async
Motivation:
  - Add docs for Destroy async. I think I probably need to add
    information about setting up active job, but I am not sure where we
    want this, so I am putting this together to start conversation.

Related Issues:
  - #41093

* Active Job not ActiveJob

* Fix some spelling issues

[Cory Gwin, Rafael Mendonça França, Eileen M. Uchitelle, Henrik Nyh]
2021-03-24 00:54:50 -04:00
Ryuta Kamizono
89719d474b
Merge pull request #41747 from kamipo/prefixed_internal_methods
Add `_` prefix for the internal methods
2021-03-24 13:52:16 +09:00
Rafael França
419b0785b3
Merge pull request #41725 from okuramasafumi/add-more-examples-to-routes-shallow-doc
[skip-ci] Add table for shallow routing to routing doc
2021-03-24 00:49:47 -04:00
Dylan Thacker-Smith
097e4afcba Add an assertion to the regression test
Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2021-03-23 21:41:36 -07:00
Ryuta Kamizono
12c0bec152 Add _ prefix for the internal methods
Add `_` prefix for the internal methods since `saving?`, `can_save?`,
and `saving` are too shorter naming for the internal methods, it can
easily be overridden by the user defined methods.

Also, I've removed `saving?` since the internal method is used only for
testing.
2021-03-24 13:39:42 +09:00
Ryuta Kamizono
8cd3b657f8 protected :can_save?
And tweak tests added at #41714.
2021-03-24 10:54:16 +09:00
George Claghorn
35d3923ea0 Exclude #saving? from API docs
We don't have a concrete use case for it outside of AR itself.
2021-03-23 21:16:26 -04:00
Dylan Thacker-Smith
1e1fe3f7bb Move @inspection_filter to the class to avoid marshal dumping it
Previously, this was causing Marshal.dump to file to dump a record
with a Proc in the filter_attributes after inspect was called on the
record.
2021-03-23 16:48:58 -07:00
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
OKURA Masafumi
d2bbb218cb Add table for shallow routing to routing doc
Shallow routes is one of the most difficult-to-use features for
generating routes in Rails.
To make it easier to understand how it works, a routing table
shows us the final result and really helps.
However, there's only one table for shallow routes and it's with
shallow_path option, which is even more complicated.
Adding a table for simpler shallow routes will help people
understand shallow routing's idea and usage better.

There's a drawback of this addition. Adding a large table occupies
the screen and might make it slightly difficult to walk through
the documentation.
2021-03-22 22:25:54 +09: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