-
Notifications
You must be signed in to change notification settings - Fork 590
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 oversights in add missing schema fields #4736
Conversation
const seen = new Set(); | ||
const keep = {}; | ||
for (const key of Object.keys(changes)) { | ||
// MongoDB won't tolerate $set for both |
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.
It seems like the existing unit tests should have caught this, so I don't know of a good way to test it better, but in testbed this did come up and required the fix I have implemented here.
@@ -54,8 +90,10 @@ module.exports = (self) => { | |||
addMissingSchemaFieldsFor(doc, schema, dotPath, changes) { | |||
for (const field of schema) { | |||
const newDotPath = dotPath ? `${dotPath}.${field.name}` : field.name; | |||
// Supply the default | |||
if (doc[field.name] === undefined) { | |||
// Supply the default if a field is undefined, and also in the |
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.
Not really our fault per se if the object field had a weird non-object value rather than being undefined, but it happened "in the field" with testbed, so fix it!
@@ -91,7 +129,10 @@ module.exports = (self) => { | |||
} | |||
} else if (field.type === 'relationship') { | |||
for (const [ key, item ] of Object.entries(doc[field.fieldsStorage] || {})) { | |||
const itemPath = `${newDotPath}.${field.fieldsStorage}.${key}`; |
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.
This was the wrong path.
@@ -101,7 +142,7 @@ module.exports = (self) => { | |||
getPropLists() { | |||
const schema = {}; | |||
for (const [ name, module ] of Object.entries(self.apos.doc.managers)) { | |||
if (!module.__meta.name) { | |||
if (!module.__meta?.name) { |
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.
Fake managers have no __meta
so this wasn't tolerant enough.
@boutell we might need to explain in the doc the new behavior, if the field value does not exist, set the value to something other than the default |
Good point, we should document this in the migrations docs. |
* main: fix oversights in add missing schema fields (#4736)
* upstream/main: fix oversights in add missing schema fields (apostrophecms#4736) upgrate stylelint-config-apostrophe to 4.2.0 (apostrophecms#4735) PRO-6472: at startup, automatically supply a value for any new schema property that has a def or fallback def (apostrophecms#4721) fix sass warning (apostrophecms#4730) fix piecesFilters with dynamic choices (apostrophecms#4731) hotfix 4.7.1 (apostrophecms#4733) PRO-6591: parked fields overrides (apostrophecms#4732) do not let a page become a child of itself (apostrophecms#4726)
Fix issues that came up in testbed.