I'm just going through some code in an application and adjusting it to work with Django 1.3 and I thought I'd have to fix a portion of code to account for the change in transactions meaning that a cursor.execute call would leave a transaction in a dirty state (even tho' it didn't change anything). I was surprised to find on the development server that no error was raised.
Looking into the code, I don't think http://code.djangoproject.com/ticket/15289 has been fully fixed... Because CursorDebugWrapper defines its own execute and executemany methods then calls in debug mode to cursor.execute() and cursor.executemany() will not leave the transaction dirty if it's managed (because __getattr__ won't be called for those two methods). I'm also a bit perplexed actually by the bit in CursorWrapper.__getattr__ that looks in self.__dict__ - maybe my python knowledge is a bit rusty, but if the attr was already in self.__dict__ then surely __getattr__ would not get called (the only time this wouldn't be the case would be if it wasn't there at the start of the call to __getattr__ but something else put it in there, however the calls to self.db methods won't do that)? The two choices I see are: First is to add the two lines to each of the two methods in CursorDebugWrapper to set the dirty flag when appropriate (and remove the redundant bit of code about self.__dict__ from __getattr__, assuming I'm right about that!). Second is to replace __getattr__ with __getattribute__ such that truly any attribute access on a wrapped cursor, including subclasses, will go through the dirty flag setting, although more care is needed if that is done because you can't even access self.__dict__ directly without __getattribute__ going off - a call has to be made to the object.__getattribute__ - so self.db and self.cursor would need to be fished out using that. I wasn't sure about reopening #15289 or raising a new ticket, so thought I'd post here to ask about the best course of action (assuming I'm spot on in my assessment of the situation). Regards, Matt -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.