Skip to content

Fixed import for tags without slugs belonging to a post#10917

Merged
naz merged 5 commits into
TryGhost:masterfrom
naz:importer-tag-without-slug-bug-fix
Jul 16, 2019
Merged

Fixed import for tags without slugs belonging to a post#10917
naz merged 5 commits into
TryGhost:masterfrom
naz:importer-tag-without-slug-bug-fix

Conversation

@naz
Copy link
Copy Markdown
Contributor

@naz naz commented Jul 15, 2019

closes #10785

The change adds a fallback to use the original id property of imported object when handling relations, this was ignored previously. The main change here was around beforeImport method in the Importer base class, so that id property substitution is trackable.

naz added 2 commits July 15, 2019 18:21
closes TryGhost#10785

- The behavior for tags will now be similar to posts' one described in the docs
- "The only strictly required field when importing posts is the title. Ghost will automatically generate slugs and set every other field to the default or empty."
- The breaking change was introduced with: TryGhost@68d8154#diff-e712df50c0dc7cf33746eeff0564003cR97 (assumed there's always slug in imported object which is not true)
- Added originalIdMap to the importer base class to track id
substitution so it can be used when dealing with relational resource
updates
- Removed explicit use of 'this.stripProperties(['id']);' in
beforeImport of base class because we need to assign and remove the id
property in the same place to track this change
- Only callingi 'this.stripProperties(['id']);' in
settings/trusted_domain imports as the method wont be called otherwise
- Expanded regression tests with new supported import case
@naz naz requested a review from allouis July 15, 2019 16:31
Copy link
Copy Markdown
Collaborator

@allouis allouis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall changes seem to make sense, just come questions/comments about edge case and explicitness in tests 👍

Comment thread core/test/regression/importer/importer_spec.js
if (objectInFile.slug) {
importedObject = _.find(this.requiredImportedData[tableName], {originalSlug: objectInFile.slug});
} else {
importedObject = _.find(this.requiredImportedData[tableName], {originalId: objectInFile.id});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check for the existence of objectInFile.id?

I noticed above that the originalIdMap doesn't necessarily contain an entry for every id - just trying to work out if there's an edge we're missing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The objectInFile.id is always there because of this bit. But you are right, making it else if (objectInFile.id) makes it proof to accidental === undefined comparisons in case id assigning code changes in the future 👍

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaah I see! Yup that makes sense ☺️

One more thing, what is the reason to attempt to match on slug first? Could we just always match on the id and remove the conditional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point! Was thinking of slug matching as a fallback, but after rereading the previous statement there's no point in keeping it as the originalId will always be accessible 💡

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 !!

Copy link
Copy Markdown
Collaborator

@allouis allouis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably remove a few if statements now if you want - but up to you - merge at will

@naz
Copy link
Copy Markdown
Contributor Author

naz commented Jul 16, 2019

Leaving the if for the reason mentioned in the comments:

if (objectInFile.id) makes it proof to accidental === undefined comparisons in case id assigning code changes in the future +1

🚢

@naz naz merged commit 9dcc17a into TryGhost:master Jul 16, 2019
@allouis
Copy link
Copy Markdown
Collaborator

allouis commented Jul 16, 2019

Good call 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importer: multiple relationships not handled if objects don't have slugs

2 participants