Ticket error_handling

I just passed the tests but still get error when checking in the status page. This is the exception:

except (StopIteration,InvalidId) as _:

    """
    Ticket: Error Handling

    Handle the InvalidId exception from the BSON library the same way as the
    StopIteration exception is handled. Both exceptions should result in
    `get_movie` returning None.
    """

    return None

This is the test result:

^C(mflix_venv) MacBook-Pro-de-Carlos:mflix-python carlosherrera$ pytest -m error_handling
================================================================ test session starts ================================================================
platform darwin – Python 3.7.0, pytest-3.9.1, py-1.7.0, pluggy-0.8.0
rootdir: /Users/carlosherrera/Documents/MongoDB/M220/mflix-python, inifile:
plugins: flask-0.10.0
collected 35 items / 34 deselected

tests/test_error_handling.py . [100%]

================================================================= warnings summary ==================================================================
/Users/carlosherrera/Documents/MongoDB/M220/mflix-python/mflix_venv/lib/python3.7/site-packages/pytest_flask/plugin.py:109: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/carlosherrera/Documents/MongoDB/M220/mflix-python/mflix_venv/lib/python3.7/site-packages/pytest_flask/plugin.py:61: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/carlosherrera/Documents/MongoDB/M220/mflix-python/mflix_venv/lib/python3.7/site-packages/pytest_flask/plugin.py:78: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

– Docs: https://docs.pytest.org/en/latest/warnings.html
================================================ 1 passed, 34 deselected, 3 warnings in 0.13 seconds ===

But the status page says: Errors: The return from the api was incorrect when providing a bad id to search by

Anyone else has encountered this?

1 Like

I am running into the same issue. The pytest for error handling passed, but on status, I am getting the same error.
Errors: The return from the api was incorrect when providing a bad id to search by

I’m having the same issue.

I’ve tried adding a check of
if not ObjectId.is_valid(id):
return None
It appears that solves the issue of the complaint on the console, but the status page still just gives the red error box, no hash code… :frowning:

Someone pointed out that downloading the newest version of the mflix code (from the zip in Chapter 0) fixes the problem… :man_facepalming:

Remove the StopIteration from except statement, only InvalidId is neccesary.

My test pass with two exceptions: StopIteration and InvalidId.

The StopIteration is there to catch a different potential error. You should not remove it.

1 Like

I tried removing the StopIteration but doesn’t fix the problem

Please ensure you’ve download the newest version of the handouts.

You should be able to suppress the error with except Exception as e: for now, but if you look in the debug output in your console/terminal/shell you’ll see what the error is triggered by!

1 Like

Ops, I mean for test purposes, sorry.

I just see that in console: 127.0.0.1 - - [05/Nov/2018 19:20:10] “GET /api/v1/movies/id/foobar HTTP/1.1” 400 -

Even " except Exception as e:" does not make the test pass…

I’m using last version of the handouts…

something very weird

that works on updated *.zip from handout :
# except (StopIteration) as _:
except InvalidId as e:

Indeed I solved downloading the newest version of the handouts

Which is “newest”? I used the one in handouts section from yesterday and does not work…

@dscarlat,

Could I bother you to put what you have in a git repo and dm me the link? I’d really like to take a look at what’s going on.

Hi Nathan, I uploaded it to github.

Edited to remove github link.

@dscarlat
Thanks, taking a look now!

@dscarlat,

Ok, I had a look. I forked and cloned the repo, and ran it locally.

First, well done! Second, I’ve made a PR to your repo to fix this issue. You’ve also helped me identify the root issue so that I can fix this for other students.

I apologize for the headache over this.

Kudos @nathan.leniz, thanks for the Mongo DB university courses, it is a great idea.