Commit 04a3fe3
Ensure linting transactions don't interfere with ActiveRecord lifecycle
Our FactoryBot linting started failing for a factory despite evidence
that the trait combination was producing a valid model in test. We
eventually traced that down to the change made in #1726. Introducing a
`ActiveRecord::Base.transaction` meant that the `after_commit` hooks of
our model weren't running during linting.
This is because of the way `ActiveRecord::Base` handles transactions.
When changes are inserted for an ActiveRecord within an
`ActiveRecord::Base.transaction`, that transaction keeps a list of all
the records it contains changes for. as part of the transaction
committing, `*_commit` record callbacks are fired
`ActiveRecord::Base.transaction`s are `joinable` by default, which means
that `ActiveRecord` can choose to join an existing transaction instead
of inserting a new one. This means that `*_commit`s that would
previously result from the object's lifecycle are not sent until the end
of the linting transaction.
To reinstate the previous behaviour, this PR ensures that the linting
transaction is not joinable and any `*_commit` callbacks are
respected.1 parent 27e97b4 commit 04a3fe3
2 files changed
+18
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
47 | 64 | | |
48 | 65 | | |
49 | 66 | | |
| |||
0 commit comments