M220P - Update and Delete comments work, but not the validation

Here is my code for the update. Why is the validation not working?

def update_comment(comment_id, user_email, text, date):
response = db.comments.update_one(
{ “_id”: ObjectId(comment_id), “email”: user_email },
{ “$set”: { “text”: text, “date”: date } }, upsert=True
return response

Here is the code for the delete. Same question…

def delete_comment(comment_id, user_email):
response = db.comments.delete_one( { “_id”: ObjectId(comment_id),“email”: user_email } )
return response

Hi @Patrick_45742,

You don’t need to insert a comment while performing update operation.

Code for delete function looks right to me.

What is the error messages when you run the unit tests?


@Kanika No error message. The code works. I am not doing any insert. I have added the upsert statement when I noticed it was not working, but deleting it would not change anything.

Can you please share this here.


I get a red messaged posted and stating: Create/Update Comments: Unable to update comment, instead of a green code to parse for validation.

This means the Insert works, but not the Update. But, the problem is that when I test with the application, it all works fine.

Same issue with the delete. It works and I get: Delete Comments: Deletion was performed but unsuccessful

Please share.


I have the same problem.
My code is ok, but can not update or delete comments.

Hi @ANTONIO_39769,

We would love to help. Please share the error messages here.


I had similar issues with add/update comment as well as for delete comment despite having the right solution (I know it because I failed those two and then checked the suggested solution which was the same as my solution). I have taken snapshots of the error messages I got during the unit tests. I am getting similar error messages again for the Tickets in Chapter 4 on Resiliency. Pls see attached errors during the test.

. I have also attached the error I see on validation.
Pls help. I don’t want to fail these labs unnecessarily in Chapter 4 too!

Hi @chetankshetty,

Seems like a network issue. Make sure you are using localhost to get the validation code. Let me know if this post helps.


422 error while running the unit test

for update comments snippet

Hi @Farook_95295,

There must be some other error messages along with 422 code. Please check and you will be able to debug the code from there.

If not, please share the whole output when you run the unit test case.