🐛 Fixed URLs not being correctly transformed during insert operations#13618
Merged
kevinansfield merged 2 commits intoTryGhost:mainfrom Oct 20, 2021
Merged
Conversation
refs TryGhost/Product#1150 Our override of the base Bookshelf `insert` operation so that our own `formatOnWrite()` method is called on attributes was working on a false assumption that an `attrs` attribute is passed in as it is for the `update` operation. Instead Bookshelf's base update uses the `model.attributes` values to create an `attrs` object that is then passed through the usual `.format()` method meaning that our `insert` override was not actually doing anything. - added a failing regression test for the `formatOnWrite()` override behaviour - adjusted our insert/update overrides to set an internal `_isWriting` property on the model, then if that property is true our `.format()` override (which is called by Bookshelf on a generated `attrs` object during inserts) we manually call our `.formatOnWrite()` method - updated both overrides even though `update` was working for consistency and less cognitive overhead for reasoning between two different approaches
naz
reviewed
Oct 19, 2021
| const models = require('../../../../core/server/models'); | ||
|
|
||
| describe('Models: Base plugins: Overrides', function () { | ||
| before(testUtils.teardownDb); |
Contributor
There was a problem hiding this comment.
Love that we have test coverage for more and more pieces of the model 🖤
It's totally outside the scope for this issue, just me thinking out loud 😅 Would be cool to not have extremely expensive teardown/setup cycles in unit tests. Something like what we have with the migration tests would be much more suitable imo. We don't measure this, but essentially each all test cases add ~300ms on average to run because of the hidden cost of db operations 🙀
Contributor
There was a problem hiding this comment.
To be clear, nothing to do with this right now! Just making a mental note to pay closer attention to the before/after clauses setting up db state :)
naz
reviewed
Oct 19, 2021
naz
approved these changes
Oct 19, 2021
daniellockyer
approved these changes
Oct 20, 2021
Co-authored-by: naz <nazargargol@gmail.com>
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.
refs https://github.com/TryGhost/Team/issues/1150
Our override of the base Bookshelf
insertoperation so that our ownformatOnWrite()method is called on attributes was working on a false assumption that anattrsattribute is passed in as it is for theupdateoperation. Instead Bookshelf's base update uses themodel.attributesvalues to create anattrsobject that is then passed through the usual.format()method meaning that ourinsertoverride was not actually doing anything.formatOnWrite()override behaviour_isWritingproperty on the model, then if that property is true our.format()override (which is called by Bookshelf on a generatedattrsobject during inserts) will manually call our.formatOnWrite()methodupdatewas working for consistency and less cognitive overhead reasoning between two different approaches