Ticket: Migration test error

I’m stuck in the Ticket migration, it requires to edit the “movie_last_updated_migration.py” file.

Is there any way to check it step by step to understand where is the error?

I updated the host

  1. host = “mongodb+srv://m220student:m220password@mflix-XXXX.mongodb.net”

  2. predicate: OK Checked with Compass. Just updated the true to capital letter for python True.
    projection: None (kept none, not required (optional))

  3. bulk_updates: filled the $set

Any suggestion?
Thanks

The problems seems to be the “movie_last_updated_migration.py” was never called.

You could try to run the file and then execute the test.

On the command line:

  1. cd ……\mflix-python\migrations
  2. python movie_last_updated_migration.py
  3. cd …
  4. pytest -m migration

Regards

1 Like

Thanks Kevin,

You were right, the “movie_last_updated_migration.py” was never called.

Once executed the command: python movie_last_updated_migration.py, starts the migration.

46014 documents to migrate
46014 documents updated

Thanks a lot

1 Like

Please help me. I changed the code but my results:
46013 documents to migrate
46013 updated

pytest: ok


But, I can’t generate a code:

Guys, I found the error. The quantity of registries were incorrect. Perhaps I have deleted some registry on another lesson accidentally. The right number of registries is 46014, not 46013.
Ticket finished sucessfully!

Thanks Kevin… Your suggestion helped me too in resolving the issue.

Can anyone suggest a way to examine why my code is failing the test.

I am getting an assertion error that the lastupdated field is not of type datetime.

 assert isinstance(result.get('lastupdated'), datetime)
        AssertionError: assert False
         +  where False = isinstance('2015-02-03 00:25:58.217000000', datetime)

I have set my predicate and tested it out in Compass and a Jupyter notebook. By running the file without the bulk_updates operation I get 45993 documents to migrate, so my predicate is picking up all the documents.

The first document in movies_to_be_migrated is:
{'doc_id': ObjectId('573a1390f29313caabcd4132'), 'lastupdated': datetime.datetime(2015, 8, 26, 0, 3, 45, 40000)}

So parser.parse(lastupdated) has worked.

For the bulk updates, the first document to be updated is:
UpdateOne({'_id': ObjectId('573a1390f29313caabcd4132')}, {'$set': {'lastupdated': datetime.datetime(2015, 8, 26, 0, 3, 45, 40000)}}, False, None, None)
The value to be updated is a datetime.datetime object. The final 3 parameters are the pymongo defaults of upsert=False, collation=None, array_filters=None

So, in conclusion,

  • I’m updating all the docments

  • The lastupdated is being converted

  • The update should be overwriting the existing string with a datetime.datetime object

  • But the vaildation test fails.

  • The inference is that my $set is incorrect and no documents are actually being updated. I’ve tested out the format in a Jupyter notebook and it seems to be correct.

Anyone got any ideas?
Thanks

Who knows?
I shut everything down, went and had lunch, then came back and tried it again.
It worked.
Good grief :roll_eyes:

1 Like

Thanks Kevin!
It helped me as well.