Django: Debugging and empty objects


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.


Hanan_Natan wrote Mar 10 at 11:28 AM

This bug really needs to be escalated.
I have lost so much time until i found out that it is a bug :(

Zooba wrote Mar 10 at 2:25 PM

You're right, I missed seeing this one come in.

At a guess I'd say those attributes don't exist until you get them (via __getattr__) which we don't invoke through the debugger because it makes every possible name a possibility. Maybe we should see if we can make a call when an attribute name is provided though, rather than using what the object had when the frame was sent.

At least, we should display a message for those attributes saying they don't exist on the object (maybe with the refresh button?)

pminaev wrote Apr 3 at 1:35 AM

How would we know that they don't exist but should, though? Or do you mean data tips?