Music: Living Voyage by Kevin MacLeod is licensed under a Creative Commons Attribution 4.0 license. creativecommons.org/licenses/by/4.0
Fixing the Bug
00:00 Alright, so there is an error here that’s not working in the way that I want it to work. I’m getting an “Unprocessable content” when I’m trying to receive the items in randomized order.
00:11 So here I want to show you how you can resolve a bug like that. I’m going to start a new agent. And what you can do with this built-in browser is you can go to the top right and click this little icon with the cursor and the screen that says “Select element.” When I click it, I can select all elements on that webpage.
00:32
And now I’m just going to try to fetch the whole div that gives me items randomized.
00:38 As you can see, it adds it here, the whole context in this compressed little button type thing. Okay, now I’m going to give it a little bit of extra context.
00:47 I’m going to also mention what the problem is.
00:50 “I’m expecting to get back randomized items, but instead I get an error.”
01:03 And now let’s see if – there’s information, you can see, you can hover also to see what’s all the information that it gets back. Here you get the delete items in the text – should be in there.
01:15 Actually, just to be sure, I’m also going to copy this error message and just throw it in there. I’m just giving it more context
01:23
and then let’s see what it says to that and if it helps me to fix that error. So FastAPI is matching /items/randomized to, and here’s already a solution. FastAPI is – let me read that please.
01:36
FastAPI is matching /items/randomized to /items/{item_id} because the parameterized route is defined first, checking the current route definition.
01:44
So it looks over there and it tells me that this route, the randomized route, is defined after /items/{item_id} and item_id expects an integer as input, so it matches randomized as item_id.
01:56 And that gives us this integer parsing error that you can see here on the right.
02:01
So the solution is that you can just reorder those routes. So it’ll go ahead and move those over. So in main.py, it’s moving this function that’s here at the end and moves it somewhere up here.
02:13 We should have a green insert here. That looks great. So I can say keep that change. Yes, and keep the deletion as well. So I moved it up here. The app should have reloaded, so let’s go ahead and try it out again.
02:27 If I now click on Execute, now I still get the same error, so maybe I need to reload the app myself.
02:35 Yeah, so we’re getting the same error. So let’s double check that it’s running. “Unprocessable content,” So this is running, so I just brought up the terminal using a keyboard shortcut that again is the same as in VS Code And then I pressed the keyboard shortcut Control + C to stop the server that’s running here.
02:58 And you can see on the right side in the tab that shows the different terminals, there’s this infinity symbol, and that just means that it’s a terminal tab that Cursor started and that it keeps running in the background until, for example, I stop it manually, which I just did now.
03:19 Now I want to restart the server, but I’ll do that in the next lesson because I also want to make sure that I can interact with it through my own terminal, not only the terminal that Cursor is using.
Become a Member to join the conversation.
