[Django] #28091: Hiding 'cursor does not exist' error doesn't work

14 views
Skip to first unread message

Django

unread,
Apr 18, 2017, 4:35:17 AM4/18/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude | Owner: nobody
Paroz |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In commit [6b6be692fcd102436c7abef1d7b3fa1d37ad4bdf], Django tries to mask
the 'cursor does not exist' exception because it masks the real database
exception. Unfortunately, the commit is not fulfilling its promise, as the
`raise` command just after the `pass`, will in fact raise the second
exception (the one we are trying to mask) not the original one.

--
Ticket URL: <https://code.djangoproject.com/ticket/28091>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 18, 2017, 11:08:38 AM4/18/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Unfortunately, until now, I wasn't able to reproduce the error with the
Django test suite. In my project, I had a new model which was not yet
migrated, but even with that scenario, I was not able to reproduce on
Django. Any help welcome, as I think a test would be really helpful here.

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:1>

Django

unread,
Apr 18, 2017, 12:58:46 PM4/18/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: assigned

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by François Freitag):

* owner: nobody => François Freitag
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:2>

Django

unread,
Apr 18, 2017, 1:32:25 PM4/18/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: assigned
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by François Freitag):

Hi Claude,

I have
[https://github.com/django/django/compare/stable/1.11.x...francoisfreitag:28091/hide_cursor_does_not_exist?expand=1
a test] that's failing before [6b6be692fcd102436c7abef1d7b3fa1d37ad4bdf]
and passes after this commit.
Were you able to gather more information about your failure?

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:3>

Django

unread,
Apr 18, 2017, 2:05:08 PM4/18/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: assigned
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

I'm getting that:
{{{
======================================================================
ERROR: test_cursor_close_failure_does_not_mask_original_exception
(backends.tests.BackendTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/claude/checkouts/django-git/tests/backends/tests.py", line
695, in test_cursor_close_failure_does_not_mask_original_exception
mock_cursor.execute =
mock.MagicMock(side_effect=raise_original_exception)
AttributeError: 'psycopg2.extensions.cursor' object attribute 'execute' is
read-only
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:4>

Django

unread,
Apr 18, 2017, 2:27:17 PM4/18/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: assigned
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by François Freitag):

I updated the test because my cursor creating was flawed. I should have
used directly connection.chunked_cursor() instead of trying to be smart
and use create_cursor().

Fixing this error made the test fail with:
{{{
FAIL: test_cursor_close_failure_does_not_mask_original_exception


(backends.tests.BackendTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):

File "/usr/lib64/python2.7/unittest/case.py", line 329, in run
testMethod()
File "/home/freitafr/dev/django/tests/backends/tests.py", line 700, in
test_cursor_close_failure_does_not_mask_original_exception
list(persons)
File "/usr/lib64/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/home/freitafr/dev/django/django/test/testcases.py", line 615, in
_assert_raises_message_cm
self.assertIn(expected_message, str(cm.exception))
File "/usr/lib64/python2.7/unittest/case.py", line 803, in assertIn
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/lib64/python2.7/unittest/case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: u'Real exception raised by the database on cursor.execute'
not found in 'Error when attempting to close the cursor, would mask the
actual exception'
}}}

I opened [https://github.com/django/django/pull/8371 #8371] with a
suggested way to fix this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:5>

Django

unread,
Apr 20, 2017, 11:44:01 AM4/20/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: closed

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"56746fb21f6bbf93fe96f4e3908040111439c9c3" 56746fb2]:
{{{
#!CommitTicketReference repository=""
revision="56746fb21f6bbf93fe96f4e3908040111439c9c3"
[1.11.x] Fixed #28091 -- Re-raised original exception when closing cursor
cleanup fails
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:6>

Django

unread,
Apr 20, 2017, 12:58:31 PM4/20/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"c9d933ba999ef0c3b37045335715d93e92ddb279" c9d933ba]:
{{{
#!CommitTicketReference repository=""
revision="c9d933ba999ef0c3b37045335715d93e92ddb279"
[1.11.x] Refs #28091 -- Fixed typo and rephrased 1.11.1 release note.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:7>

Django

unread,
Apr 20, 2017, 12:58:43 PM4/20/17
to django-...@googlegroups.com
#28091: Hiding 'cursor does not exist' error doesn't work
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: François
| Freitag
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8b767986bacaf55ed8d87ca1228002e8a6c259c6" 8b767986]:
{{{
#!CommitTicketReference repository=""
revision="8b767986bacaf55ed8d87ca1228002e8a6c259c6"
Refs #28091 -- Forwardported 1.11.1 release note.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28091#comment:8>

Reply all
Reply to author
Forward
0 new messages