Create/Update Comments: Unable to update comment

I’ve read all the related topics and output all the information already. Still cannot figure it out. Does anyone have some suggestions on it?

Thank you
Kai

Poxt related unit tests results.

Your post indicate 43 deselected on 43 collected. It means you have not specified an appropriate test case.

I thought I ran “pytest -m test_create_update_comments” is to specify a test case.

I know that this is what you did as it is clear from your screenshot.

It is also clear that this test does not match any test you have in your tests directory. I went back back to the course to see what is wrong. Did you run any other tests before? I am asking that because you do not invoke the tests as indicated in the lecture.

Testing and Running the Application

You can run the unit tests for this ticket by running:

pytest -m create_update_comments

You really must follow the instructions.

1 Like

Hi Steeve,

I solved the problem through knowing how to run pytest correctly. Actually I didn’t have any problem in the create_update_comments test, I failed part of the get_comments test. After I added the comments_should_be_sorted_by_date code and passed the get_comments test, I passed the create_update_comments test without changing anything.

Thank you very much
Kai

1 Like



All the unit tests were passed but still unable to get validation key, can any one help

Hi @guru_sai - welcome to the forums,

Can you re-post this in a new topic so that we can work to address your specific issue? If you could also include the output from the application so that we can see what explicit error message it gave when it failed to update the comment as this will be useful to understand what is occurring with your code?

Kindest regards,
Eoin

Hi everyone,

I just now faced an issue looking very similar to what you’re discussing: pytest -m create_update_comments passes all tests, but I every time got this ‘Unable to update comment’ in the frontend app.

It was actually my fault, and in the end I realized what was wrong. I won’t paste this ticket’s solution here for obvious reasons, though would like to share what helped me.
In the method ‘update_comment’, where comment_id argument is used, I just used it as is, and forgot that it’s just a string. While ID values in MongoDB are wrapped like:
ObjectId(something). So after I changed usage(s) of ‘comment_id’ in this method to ‘ObjectId(comment_id)’ (and restarted the python run.py) - I was able to get the solution key from the frontend app.

But I’m actually thinking that pytest should’ve captured this mistake.

P.S. Don’t forget, that challengers should apply the above to other methods if/where applicable.
best wishes, leonid

3 Likes

Hi @Leonid_Orlov

Thanks for the post and the changing of the string type is a deliberate choice within the exercise. It is not a mistake but rather an explicit choice we’ve made to help ensure a better understanding of MongoDB at the end of the course.

Hope this helps explain the rationale and congratulations on completing the lesson.

Kindest regards,
Eoin

Hi all, I’m having the same issue: “Unable to update comment”. I’ve tried to apply all the suggestions I found here, but nothing changed. What’s wrong with my code?

Thank you for the support!

What about the following?

I do not see that in your code.

@steevej I change the comment_id in ObjectId(comment_id) before the update query. Anyway, even applying what you say I have the same result.

Thank you

was facing the same issue, this really helped