﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20897	Asymmetrical cursor creation in django.db.backeds.BaseDatabaseWrapper	emil.filipov@…	nobody	"We currently have the following cursor creation code in BaseDatabaseWrapper:
{{{
    def cursor(self):
        self.validate_thread_sharing()
        if (self.use_debug_cursor or
            (self.use_debug_cursor is None and settings.DEBUG)):
            cursor = self.make_debug_cursor(self._cursor())
        else:
            cursor = util.CursorWrapper(self._cursor(), self)
        return cursor
}}}

The issue I have with this piece of code is that the cursor is created in a very different way, depending on whether we have a debug mode or not. The symmetrical way of doing it would be to call something like ''self.make_regular_cursor(self._cursor())'' for the cursor creating in the regular case.

Use case:
Modules like Django Debug Toolbar wrap the ''.cursor()'' invocation on the base class, it's all working nicely for the standard backends, that do not override ''cursor()''. The problem, however, becomes apparent when you write your own backend, that overrides the ''cursor()'' method. Then you have to call the parent method, to ensure compatibility with DDT, but that parent method will either return the generic Cursor class (for a regular cursor), or your own, custom Cursor class (for a debug cursor, where you have overridden ''make_debug_cursor()'') - a situation requiring a decision based on the type of the returned argument.

Patch:
Fairly trivial - just add another member function and wrap  ''util.CursorWrapper(self._cursor(), self)'' inside it. I can provide one if needed."	Cleanup/optimization	closed	Database layer (models, ORM)	1.5	Normal	fixed		emil.filipov@… Tim Martin	Accepted	1	0	0	0	0	0
