Skip to content
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

UI: Fix empty item on kv list #22838

Merged
merged 17 commits into from
Sep 12, 2023
Merged

UI: Fix empty item on kv list #22838

merged 17 commits into from
Sep 12, 2023

Conversation

hashishaw
Copy link
Contributor

@hashishaw hashishaw commented Sep 6, 2023

There is a bug in our version of ember-data (4.11.x) where after editing a record, going to the list page would result in a ghost record because unloadAll wasn't unloading everything properly. As part of the investigation I found a couple other issues that I cleaned up as well.

Replication steps for initial issue:

  1. Have a few secrets created in a KV v2 engine
  2. Go to a secret detail
  3. Click "Metadata" tab
  4. Edit metadata, add custom metadata
  5. Save
  6. Click the breadcrumb to go back to the secrets list
  7. Ghost item exists on the list

We decided not to upgrade to ember-data@4.12 at this time (the version which has a fix), because after upgrade other tests were failing with expected stable identifier issues, and the upgrade requires store configuration which we didn't want to rush to get in before code freeze without adequate testing.

@hashishaw hashishaw added this to the 1.15 milestone Sep 6, 2023
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Sep 6, 2023
@@ -138,13 +138,23 @@ export default class StoreService extends Store {
return resp;
}

forceUnload(modelName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting find!

@@ -46,9 +46,15 @@ export default class KvSecretsListRoute extends Route {
});
}

getPathToSecret(pathParam) {
Copy link
Contributor

Choose a reason for hiding this comment

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

much cleaner, thank you!

ui/app/services/store.js Outdated Show resolved Hide resolved
ui/app/services/store.js Show resolved Hide resolved
@@ -24,92 +22,21 @@ export default class SecretDeleteMenu extends Component {

@tracked showDeleteModal = false;

@maybeQueryRecord(
Copy link
Contributor Author

@hashishaw hashishaw Sep 8, 2023

Choose a reason for hiding this comment

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

When navigating from the details page back to the list in kv v1, the console was erroring with
Cannot create a new tag for `<model::capabilities:undefined>` after it has been destroyed
Finally tracked it down to these not tearing down gracefully, so I moved the capabilities to the model instead which is our latest pattern

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the secret-edit component also uses maybeQueryRecord so something to be aware of if we notice that error further. Interesting that it's also used in lazy-capabilities which is used a bunch but maybe it's ok when used on a model since they aren't torn down as frequently as components.

)
secretSoftDataPath;
@alias('secretSoftDataPath.canUpdate') canSoftDeleteSecretData;
get canUndeleteVersion() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This component should actually go away soon, so to simplify the changeset I just made these all getters of the same name

@hashishaw hashishaw marked this pull request as ready for review September 8, 2023 20:59
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

Build Results:
All builds succeeded! ✅

Copy link
Contributor

@zofskeez zofskeez left a comment

Choose a reason for hiding this comment

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

Great working grinding this one out and finding a work around 👏. I left a few comments and questions, nothing blocking.

@@ -24,92 +22,21 @@ export default class SecretDeleteMenu extends Component {

@tracked showDeleteModal = false;

@maybeQueryRecord(
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the secret-edit component also uses maybeQueryRecord so something to be aware of if we notice that error further. Interesting that it's also used in lazy-capabilities which is used a bunch but maybe it's ok when used on a model since they aren't torn down as frequently as components.

this.unloadAll(modelName);
this.forceUnload(modelName);
// Hack to ensure the pushed records below all get in the store
this.peekAll(modelName).length;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this is necessary but since there is already a peek in the forceUnload method it has to be done again after unloadAll?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I just sprinkled them around because I saw lots of test failures when I tried to minimize these. Hoping we can remove after upgrade.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought but I wonder if someone else ends up doing the next upgrade if it will be clear what can be removed as part of these workarounds? Maybe some extra annotations like remove after upgrade to Ember Data 4.12 would be helpful so we don't have extra peeks etc. hanging around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Added comments about removing once we upgrade to 4.12

Comment on lines +255 to +266
test('no ghost item after editing metadata', async function (assert) {
await visit(`/vault/secrets/${this.backend}/kv/edge/directory`);
assert.dom(PAGE.list.item()).exists({ count: 2 }, 'two secrets are listed');
await click(PAGE.list.item('two'));
await click(PAGE.secretTab('Metadata'));
await click(PAGE.metadata.editBtn);
await fillIn(FORM.keyInput(), 'foo');
await fillIn(FORM.valueInput(), 'bar');
await click(FORM.saveBtn);
await click(PAGE.breadcrumbAtIdx(2));
assert.dom(PAGE.list.item()).exists({ count: 2 }, 'two secrets are listed');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

ui/tests/unit/unload-test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@Monkeychip Monkeychip left a comment

Choose a reason for hiding this comment

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

This looks great to me! This PR touches some of the KV removal work that's still hanging in the wind. When this is merged I'll go ahead and update that sidebranch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed pr/no-changelog ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants