1
Vote

Django: Debugging and empty objects

description

When using the debugger, there are issues with certain classes:

For example, if you are accessing the request.Post dictionary, the dictionary will be empty if you break before you accessed it once.

Consider following view:
def post(self, request):
    post = request.POST // 1
    return HttpResponse(post) // 2
If you set a breakpoint before or at // 1, request.POST will always be empty. When you break at // 2, request.POST works as expected.

The same goes for cursor object:
def get(self, request):
    cursor = connection.cursor()
    cursor.execute("SELECT 1")
    row = cursor.fetchone() // 1
    return HttpResponse(row) // 2
If you break before or at // 1 fetchone returns None - at // 2 it works as expected.

comments