-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix new author creation error on socials #3578
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Quick links (staging server):
Login:
SVG tester:Number of differences (default views): 0Number of differences (all views): 0 Edited: 2024-05-06 14:05:32 UTC |
b23f0f8
to
45dfd27
Compare
45dfd27
to
5e7f5cb
Compare
5e7f5cb
to
97878f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments are a bit verbose in my humble o, but I can confirm this fixes the issue 🙂
tested by creating and saving an author page on master and this branch, inspected stored JSON in the DB
If this is causing issues in other places, could you update all the other GdocBase inheritors to use |
I like the verbose comments :) - thanks for fixing this, Matthieu! I agree that it would be nice to do this for all classes already in this PR |
yes, I'm indeed using long comments as a warning and a deterrent: the longer the comment the more I'll think about changing this line in the future 😄 thank you both for the review, I've updated the other classes. |
… overridden in Object.assign (#3600) *alternate solution to #3578, which had to be reverted because [this.content in GdocPost](https://github.com/owid/owid-grapher/blob/3691a52abfa41b34d7853df84df3329d80a9a187/db/model/Gdoc/GdocPost.ts#L34-L36) would be honored by _.defaults as a property not to override, but would result in the `content` property not respecting `OwidGdocContent` at run time.* ### What changed? This PR promotes GdocBase instance-level functions (e.g. `_enrichSubclassContent` as class methods. ### Why make this change? GdocAuthor (but also GdocPost, GdocHomepage and Gdoc DataInsight) are created from a GdocBase instance (only when inserting a new Gdoc) using `Object.assign(gdocAuthor, gdocBase)`. This call lists all enumerable properties on GdocBase, including instance-level functions such as `_enrichSubclassContent`, and overrides the subclass version. This leads to the subclass enrichment not being performed, and in the case of author creation, an error. ## Follow-up Promoting instance-level functions to class methods on `GdocBase` is enough to solve this issue, but we should consider whether to apply the same treatment to the GdocBase subclasses too.
fixes #3576
Both
GdocBase
instances andOwidGdocBaseInterface
objects implement the same interface. However, GdocBase instances leak methods intoloadGdocFromGdocBase
, which override subclasses implementations.With regards to overriding the
GdocAuthor
subclass with an instance of the parent class, three approaches have been reviewed:defaults
(see description in code)omitBy
(see description in code)This PR only fixes GdocAuthor, but we should expand this to all Gdoc* subclasses created by the
loadGdocFromGdocBase
factory function.