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

ErrDocumentIfNotAttached occurs when trying to remove documents in Dashboard #758

Closed
hackerwins opened this issue Jan 11, 2024 · 3 comments
Labels
bug 🐞 Something isn't working good first issue 🐤 Good for newcomers

Comments

@hackerwins
Copy link
Member

What happened:

ErrDocumentIfNotAttached occurs when trying to remove documents in Dashboard.

스크린샷 2024-01-11 오전 11 00 03

What you expected to happen:

A document should be removed if it is not attached to clients.

How to reproduce it (as minimally and precisely as possible):

Try to remove any documents in Dashboard.

Anything else we need to know?:

It is good to check the reason for the problem is documentIfNotAttached flag: #560

Environment:

  • Operating system: MacOS
  • Browser and version: Chrome latest
  • Yorkie version (use yorkie version): v0.4.12
  • Yorkie JS SDK version: v0.4.12
@hackerwins hackerwins added bug 🐞 Something isn't working good first issue 🐤 Good for newcomers labels Jan 11, 2024
@fourjae
Copy link
Contributor

fourjae commented Feb 1, 2024

Good, may i try this issue?

hackerwins added a commit that referenced this issue Jul 3, 2024
This commit addresses the issue where documents attached to a client
are not being properly detached during deactivation. Specifically,
information about document detachments are not being reflected in the
database, leading to situations where documents remain attached to a
deactivated client.

By this fix, attempting to delete a document from the dashboard will
now correctly handle the scenario where the document is attached,
resolving the problem outlined in issue #758.

---------

Co-authored-by: Youngteac Hong <[email protected]>
@raararaara
Copy link
Contributor

This issue occurred because the document was not properly detached when the client was deactivated. This has been modified in #907 to ensure that document detachment is correctly reflected when deactivating a client.

After these modifications are applied, correction logic is required for clientInfos with deactivated status that already have attached documents.

Through the query below, you can search for documents that meet the conditions and perform modifications on each.

db.clients.find({
  status: 'deactivated',
  documents: { $ne: null },
  $expr: {
    $gt: [{
      $size: {
        $filter: {
          input: { $objectToArray: "$documents" },
          as: "doc",
          cond: { $eq: ["$$doc.v.status", "attached"] }
        }
      }
    }, 0]
  }
}).forEach(doc => {
  var updatedDocuments = {};

  for (var key in doc.documents) {
    if (doc.documents[key].status === 'attached') {
      updatedDocuments[key] = {
        status: 'detached',
        client_seq: 0,
        server_seq: 0
      };
    } else {
      updatedDocuments[key] = doc.documents[key];
    }
  }
  
  var currentTime = new Date();

  db.clients.updateOne(
    { _id: doc._id },
    { 
      $set: { 
        documents: updatedDocuments,
        updated_at: currentTime
      } 
    }
  );
});

@hackerwins
Copy link
Member Author

This was fixed by #907

@github-project-automation github-project-automation bot moved this from Todo to Done in Yorkie Project Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working good first issue 🐤 Good for newcomers
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants