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

Bugfix challenge tags to normal tags after a challenge has ended/deleted #12341

Merged

Conversation

tsukimi2
Copy link
Contributor

Fixes #12276

Bugfix challenge tags to normal tags after a challenge has ended/deleted and added associated test cases.

Note

When running the newly added test cases, I noticed the following warnings, which I do not have any idea how to fix. Hopefully somebody can point me to the right direction? Thanks.

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

---> at src/components/tasks/user.vue

@paglias
Copy link
Contributor

paglias commented Jun 29, 2020

Hi @tsukimi2 , I gave a look at the code (thanks for the client side test!) but it seems to simply add a check for tag.challenge being the string version of true - which I don't think ever happens? tag.challenge is either undefined or true as a boolean

@paglias
Copy link
Contributor

paglias commented Jun 29, 2020

Hmm actually there's a bug here... tag.challenge gets converted to a string but should be a Boolean, let me check if there's a reason for that or not

@paglias
Copy link
Contributor

paglias commented Jun 29, 2020

Okay @tsukimi2 , after some internal talks turns out the type of tag.challenge being set to String is a bug and should be changed to Boolean It's also going to need a small migration to convert the strings to booleans. Let me know if you want to handle it in this PR, but if you can't no worries

@tsukimi2
Copy link
Contributor Author

tsukimi2 commented Jul 1, 2020

@paglias Sure, I think I can try handling the change from tag.challenge "string" to "boolean" in this PR, though probably I'll need to wait till the coming weekend to do that. Not sure whether there are other pages that are working currently based on this tag.challenge being a string currently as well. Anything I should pay attention to when trying to fix this bug?

@paglias
Copy link
Contributor

paglias commented Jul 1, 2020

@tsukimi2 thanks! AFAIK there aren't other places where this issue is present because it was treated as a boolean everywhere except that it got saved as a string which caused this bug

@paglias
Copy link
Contributor

paglias commented Jul 26, 2020

The changes are looking good @tsukimi2 , this is just going to need a migration to transform the Strings saved in the database to booleans, let me know if you want to add it or if we should handle it

@tsukimi2
Copy link
Contributor Author

@paglias Sure, I can add the migration as well.

Copy link
Contributor

@paglias paglias left a comment

Choose a reason for hiding this comment

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

Left some comments, the main issue is the use of monk but it should be easy to change


while (true) { // eslint-disable-line no-constant-condition
// eslint-disable-next-line no-await-in-loop
const users = await dbUsers.find(query, {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you import the User model

import { model as User } from '../../website/server/models/user';

and use that instead of monk? We stopped using it some time ago, you can see an example here https://github.com/HabitRPG/habitica/blob/develop/migrations/users/full-stable.js#L68

migrations/users/tag-challenge-field-string2bool.js Outdated Show resolved Hide resolved
migrations/users/tag-challenge-field-string2bool.js Outdated Show resolved Hide resolved
arrayFilters: [{ 'element.challenge': 'true' }],
};

await dbUsers.update(query, update, opts);
Copy link
Contributor

Choose a reason for hiding this comment

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

there are two update calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will there ever be a case where challenge = false? If not, then maybe I'll just delete the update on challenge false from the migration script?

@tsukimi2
Copy link
Contributor Author

@paglias Please note that the most recent push in this PR is not working yet. Just want to ask a question based on the update. Previously, when using mock (instead of mongoose) to run the migration script, it was working fine (challenge field able to change from string to boolean correctly). However, once I changed from using mock to using User model as suggested, the migration script was no longer able to change the challenge field from string to boolean anymore. I tried to issue the update query directly in mongodb and it seems to work perfectly fine. The update query is as follow:

db.users.updateOne({
_id: 'bd95ca4c-8db2-4e8d-8492-b83746b90993'
}, {
$set: {
'tags.$[element].challenge': true,
}
}, {
arrayFilters: [{ 'element.challenge': 'true' }]
});

I tried to debug the problem for quite some time but couldn't figure out what's wrong. Hope someone would provide some useful hints? Thanks.

@paglias
Copy link
Contributor

paglias commented Aug 19, 2020

@tsukimi2 I think there are 2 options here:

  1. Since we're using the User model, if you remove the .lean() call when finding the users then the result will be an array of mongoose models and you'll be able to directly change it and then call user.save() instead of making an .update()
  2. Use the $[] command documented here with a query like this
db.results.update(
   { "tags.challenge" : "true"},
   { $set: { "tags.$[].challenge": true } },
   { multi: true }
)

and

db.results.update(
   { "tags.challenge" : "false"},
   { $set: { "tags.$[].challenge": false } },
   { multi: true }
)

for false values

@paglias
Copy link
Contributor

paglias commented Sep 7, 2020

@SabreCat This is going to require the migration to be run after the PR is deployed

@paglias
Copy link
Contributor

paglias commented Sep 7, 2020

Took a bit but we made it, thanks @tsukimi2 ! Noted towards your 4th tier

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.

Challenge tags are not converted to normal tags after a Challenge link is broken
3 participants