-
Notifications
You must be signed in to change notification settings - Fork 33
fix: DH-20243: improved notebook settings merging #2593
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: DH-20243: improved notebook settings merging #2593
Conversation
dgodinez-dh
left a comment
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.
Looks like an eslint failure? But it looks like you've got a comment for the error, so I'm not sure why it's failing.
packages/redux/src/selectors.ts
Outdated
| replaceSettings( | ||
| key, | ||
| settings, | ||
| customizedSettings as UndoPartial<WorkspaceSettings> | ||
| ); |
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.
I think you can use lodash mergeWith here to deep merge keys, but don't merge arrays (the default behavior of lodash merge). Then this should be more resilient to future changes
const newSettings = mergeWith({ ......getDefaultWorkspaceSettings(store) }, customizedSettings, (objValue, srcValue) => Array.isArray(objValue) && Array.isArray(srcValue) ? srcValue : undefined)Plain merge will merge array keys. I don't know if we have any array state stored here, but merging it is probably wrong if we do?
This is the default behavior
const a = [1,2,3,4,5,6]
const b = [4,5,6]
merge(a, b) // [4,5,6,4,5,6]
mergeWith(...) // [4,5,6] using above codeThere 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.
I went ahead and replaced the whole function here with the mergeWith.
The only weird thing is the linter config. We wouldn't want that merged, correct?
I just took the approach of pulling off that config, manually determining which one we want, then putting it on top of whatever is merged. Not the most elegant and might be wasteful, but simple, and I'd need that special case either way. With the new implementation we're otherwise resilient unless we have more objects that should be replaced instead of merged.
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.
I'm not sure if merging the linter config would be a big deal. AFAIK you can turn all the rules/settings off, so merging shouldn't be an issue since you would just explicitly turn something off instead of remove it. And in some cases I think we might put an explicit default (even if it matches the omitted default in ruff) just so it's shown
Also, by not merging arrays, this would still work for the linter config as I think that's just an array of enabled rules.
Can you add a comment that says this is deep merging, but not merging items in arrays?
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.
You're right this wouldn't really matter for the rules themselves but it does look like there are some settings that aren't within arrays that could be set like line-length as a random example? Although maybe if it was set on the server then removed on the frontend we actually would want to revert to the server default instead of the ruff default. I guess I'm trying to understand if there are any settings where you'd say "if this setting is removed we should revert to the ruff default instead of the server default" but seems like that answer is no? Which is reasonable.
I've added the comment.
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.
I removed the special config logic as well. Seems like we should be reverting to a server default not a ruff default if a setting is removed, which is what would happen.
dgodinez-dh
left a comment
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.
@jnumainville I see this PR is still failing some checks. I am out until next year, so you might want to re-assign this review to someone else.
|
Yeah I'm still actively cleaning this up... I think Matt's review should be sufficient so I'll only rerequest from him (I know he's off next week too but hopefully we can get this merged tomorrow worst case). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2593 +/- ##
=======================================
Coverage 45.48% 45.48%
=======================================
Files 771 771
Lines 43591 43591
Branches 11027 11027
=======================================
Hits 19827 19827
Misses 23748 23748
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mattrunyon
left a comment
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.
Does this change alone fix the default for Ruff in DHE or will we also need a DHE change to create the settings properly on login?
|
This should fix it on DHE. This was where I traced the issue back to on DHE. |
It is expected that
getSettingssubstitutes custom settings on top of default settings when the settings are pulled.The problem is this substitution was only happening properly if top level settings were being replaced.
This meant that the nested linter settings were not getting properly replaced for
notebookSettingsbecausenotebookSettingsis never itselfundefined, only the keysconfigandisEnabledare.