how to debug in terms of different issues as a new beginner

my bug was resolved by someone else, so I guess I don’t have a particular issue to discuss about. But Im just wondering what those possible ways that y’all use to debug. Much appreciated!

Hi :slight_smile:

It really depends on what you what to debug, but the main tools I use when debugging are:

In terms of methodology their is also a lot of different options. I generally like to be able to reproduce the bug locally, it is way easier to fix this way. TDD can also sometime help to be able to test your fix in an iterative manner.

Even though it seems stupid, I often still go in there with print statements while I’m running runserver - my main goal is to work out what part of the code is misbehaving, and putting print statements with variable outputs in them all through a flow is the way I find to do that that works easiest.

If I think a codepath is happening that shouldn’t, I’ll stick an obvious runtime error in there (like raise 5) that, if it gets thrown, tells me roughly where the problem is.

Once I know the rough area of a problem, I’ll then turn to more precise tools like debuggers to work out exactly what’s happening there, though as often as not, there is simply a lot of staring at the code and running over it in my head trying to figure out what might be wrong.

i really appreciate it! but im confused about how to change Django source code and then test them. do we just import django module in our test file just like what we usually do and reproduce them? do we have to git clone the django project into virtual environment? Sorry, i have so many questions…but i really appreciate your response!

So the thing I do is pip install -e . inside the Django directory - that installs the directory directly as the version of Django your virtualenv/system is using, rather than copying it over. That means that when you change files in that Django copy, they take effect without needing to re-install or anything (and if you’re using runserver, it will even auto-reload with your changes, I believe)