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.
--
Ticket URL: <https://code.djangoproject.com/ticket/20897>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Comment:
Why not... Please make a pull request.
--
Ticket URL: <https://code.djangoproject.com/ticket/20897#comment:1>
* cc: timmartin (added)
* has_patch: 0 => 1
Comment:
I've created a pull request at https://github.com/django/django/pull/2649
I opted to call `self._cursor()` in both branches and pass the result into
`make_regular_cursor`. This isn't exactly what was suggested above, but I
think it's more regular. I can't quite picture the use case described, so
if there's something about this that won't satisfy the use case let me
know.
--
Ticket URL: <https://code.djangoproject.com/ticket/20897#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"27aa85246a218b0999c7c9d227eed2afb08ed510"]:
{{{
#!CommitTicketReference repository=""
revision="27aa85246a218b0999c7c9d227eed2afb08ed510"
Fixed #20897 -- Added make_cursor() for consistent cursor creation
In django.db.backends.BaseDatabaseWrapper, pulled the creation of
cursors in the non-debug case into a separate method, in order to
make behavior more consistent when overriding the cursor creation
in derived classes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20897#comment:3>