Issue with Update (Create and Delete work fine)

Hello everyone.
I’ve reviewed the previous topics, and I seemed to have a different issue. I can get comments, create comments and delete comments.
The flask test fails with a single issue, which is to update an existing comment created by the current user.
client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.create_update_comments
def test_update_comment(client):
    result = update_comment(comment['id'], user.email, 'foo foo foo', now)
    assert result.acknowledged is True

    comments = get_movie(movie_id).get('comments')
  assert result.raw_result.get('nModified') == 1

E AssertionError: assert 0 == 1
E + where 0 = <built-in method get of dict object at 0x7f5df4725280>(‘nModified’)
E + where <built-in method get of dict object at 0x7f5df4725280> = {’$clusterTime’: {‘clusterTime’: Timestamp(1581084399, 1), ‘signature’: {‘hash’: b’>\xf8C\xd7\xef\xd2%\xd2y\xdc-\xfe/&…\xed’, ‘keyId’: 6759214467231252481}}, ‘electionId’: ObjectId(‘7fffffff0000000000000014’), ‘n’: 0, ‘nModified’: 0, …}.get
E + where {’$clusterTime’: {‘clusterTime’: Timestamp(1581084399, 1), ‘signature’: {‘hash’: b’>\xf8C\xd7\xef\xd2%\xd2y\xdc-\xfe/&…\xed’, ‘keyId’: 6759214467231252481}}, ‘electionId’: ObjectId(‘7fffffff0000000000000014’), ‘n’: 0, ‘nModified’: 0, …} = <pymongo.results.UpdateResult object at 0x7f5df6043910>.raw_result

tests/test_create_update_comments.py:52: AssertionError

I have been testing with the mflix app using my own user, and checking with Compass.
I have created a comment. That comment shows up in the collection as verified in compass.
When I try to update, I get the following from the console (I do print(response.raw_results):

{‘n’: 1, ‘nModified’: 1, ‘opTime’: {‘ts’: Timestamp(1581083523, 2), ‘t’: 20}, ‘electionId’: ObjectId(‘7fffffff0000000000000014’), ‘ok’: 1.0, ‘$clusterTime’: {‘clusterTime’: Timestamp(1581083523, 2), ‘signature’: {‘hash’: b’\x07\xf7[x=\x94\xe3\x99{i\xe1<9v\x1f1H\xf1\r\x17’, ‘keyId’: 6759214467231252481}}, ‘operationTime’: Timestamp(1581083523, 2), ‘updatedExisting’: True}

This output seems to show that it is updating 1 record and that is is successful.
However, both compass and going out and back into comments within mlix shows no change was made to the comment.

Can anyone offer some suggestions?

Thanks,

For unit tests the database is cleaned after the tests to return it to pre-test state. This way you can run the tests many time and have the same results.

The usual problem for this is type mismatched when handling and comparing ids.

Unfortunately the unit test hadn’t cleaned out some of the comments it created. I have removed those via Compass.

I am converting the ids to ObjectId().

I am confused because it looks to me like the response from the update indicates an update was successful, but I am obviously not reading that right.

I discovered a simple typo in my update:
I did “_id:” rather than “_id”

Happy fingers causing hours of debugging.

Thanks for looking over this.

1 Like