[Django] #28859: Django hides exception from database with Oracle backend.

46 views
Skip to first unread message

Django

unread,
Nov 29, 2017, 9:48:44 AM11/29/17
to django-...@googlegroups.com
#28859: Django hides exception from database with Oracle backend.
-------------------------------------+-------------------------------------
Reporter: Jani | Owner: nobody
Tiainen |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords: oracle
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Attached minimal project to demonstrate the problem.

Traceback from Django:
{{{
Traceback (most recent call last):
File "/home/jtiai/projects/django-oracle-
bug/django_oracle_bug/django_oracle_bug/tests.py", line 6, in
test_trigger_failure
obj = MyModel.objects.create()
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/query.py", line 394, in create
obj.save(force_insert=True, using=self.db)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/base.py", line 808, in save
force_update=force_update, update_fields=update_fields)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/base.py", line 838, in save_base
updated = self._save_table(raw, cls, force_insert, force_update,
using, update_fields)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/base.py", line 924, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk,
raw)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/base.py", line 963, in _do_insert
using=using, raw=raw)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/query.py", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/models/sql/compiler.py", line 1114, in execute_sql
return self.connection.ops.fetch_returned_insert_id(cursor)
File "/home/jtiai/.pyenv/versions/django-oracle-bug/lib/python3.6/site-
packages/django/db/backends/oracle/operations.py", line 245, in
fetch_returned_insert_id
return int(cursor._insert_id_var.getvalue())
TypeError: int() argument must be a string, a bytes-like object or a
number, not 'NoneType'
}}}

Real error that happend:
{{{
ORA-01403: no data found
ORA-06512: at "ORA_TEST.TG_FAILING", line 4
ORA-04088: error during execution of trigger 'ORA_TEST.TG_FAILING'
}}}

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

Django

unread,
Nov 29, 2017, 9:49:23 AM11/29/17
to django-...@googlegroups.com
#28859: Django hides exception from database with Oracle backend.
-------------------------------------+-------------------------------------
Reporter: Jani Tiainen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jani Tiainen):

* Attachment "django-oracle-bug.tar.gz" added.

Minimal project to demonstrate the problem

Django

unread,
Nov 29, 2017, 3:06:45 PM11/29/17
to django-...@googlegroups.com
#28859: Django hides exception from database with Oracle backend.
-------------------------------------+-------------------------------------
Reporter: Jani Tiainen | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* Attachment "28859.diff" added.

Django

unread,
Nov 29, 2017, 3:11:52 PM11/29/17
to django-...@googlegroups.com
#28859: Django hides exception from database with Oracle backend.
-------------------------------------+-------------------------------------
Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0

(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => assigned
* owner: nobody => felixxm
* version: 1.11 => 2.0
* stage: Unreviewed => Accepted


Comment:

I attached minimal test in the Django test suite "28859.diff​". I'm not
entirely sure if it's a Django issue or a driver issue. Accepted for
further investigation.

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

Django

unread,
Nov 30, 2017, 2:29:23 PM11/30/17
to django-...@googlegroups.com
#28859: Django hides NO_DATA_FOUND exception from database with Oracle backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

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

Django

unread,
Nov 30, 2017, 2:34:11 PM11/30/17
to django-...@googlegroups.com
#28859: Django hides NO_DATA_FOUND exception from database with Oracle backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by felixxm):

Other exceptions e.g. `DUP_VAL_ON_INDEX`, `ZERO_DIVIDE`, `TOO_MANY_ROWS`
are raised properly.

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

Django

unread,
Dec 1, 2017, 2:37:02 AM12/1/17
to django-...@googlegroups.com
#28859: Django hides NO_DATA_FOUND exception from database with Oracle backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by Jani Tiainen):

Replying to [comment:2 felixxm]:

When testing using plain cx_Oracle exception is thrown correctly and
visible on console.
{{{
$ ./manage.py shell

In [1]: from django.db import connections

In [2]: connections['default'].connect()

In [3]: conn=connections['default'].connection # Get plain cx_Oracle
connection instead of Django wrappers

In [4]: cur=conn.cursor()

In [5]: cur.execute('INSERT INTO MYMODEL(ID) VALUES (1)')
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call
last)
<ipython-input-5-39d4fbf2986d> in <module>()
----> 1 cur.execute('INSERT INTO MYMODEL(ID) VALUES (1)')

DatabaseError: ORA-01403: no data found


ORA-06512: at "ORA_TEST.TG_FAILING", line 4
ORA-04088: error during execution of trigger 'ORA_TEST.TG_FAILING'

}}}

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

Django

unread,
Jan 1, 2018, 7:08:44 AM1/1/18
to django-...@googlegroups.com
#28859: Django hides NO_DATA_FOUND exception from database with Oracle backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by felixxm):

Replying to [comment:4 Jani Tiainen]:

`INSERT` without `RETURNING` clause raises `NO_DATA_FOUND` exception also
with a wrapped connection in Django, but when we add `RETURNING` clause,
both a `cx_Oracle` plain connection and a wrapped connection in Django
doesn't work properly, e.g.:

{{{
>>> cursor.execute('''
INSERT INTO "BACKENDS_SQUARE"("ROOT", "SQUARE")
VALUES(2,4) RETURNING "BACKENDS_SQUARE"."ID" INTO :v_id
''', {'v_id': v_id})
}}}

I raised the issue on `cx_Oracle` https://github.com/oracle/python-
cx_Oracle/issues/131.

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

Django

unread,
Jan 3, 2018, 3:30:12 PM1/3/18
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9535 PR]

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

Django

unread,
Jan 3, 2018, 3:41:06 PM1/3/18
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by felixxm):

I added workaround in the Oracle back-end, since issue will not be fixed
in the Oracle OCI library (see [https://github.com/oracle/python-
cx_Oracle/issues/131#issuecomment-355079728 comment]).

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

Django

unread,
Jan 5, 2018, 10:55:08 AM1/5/18
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin


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

Django

unread,
Jan 6, 2018, 7:27:54 AM1/6/18
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* version: 2.0 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/28859#comment:9>

Django

unread,
Jan 6, 2018, 12:51:37 PM1/6/18
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: oracle | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"8f8a93a9ae49fa807348f9f456b6635c8ebc5d0c" 8f8a93a9]:
{{{
#!CommitTicketReference repository=""
revision="8f8a93a9ae49fa807348f9f456b6635c8ebc5d0c"
Fixed #28859 -- Made Oracle backend raise DatabaseError if "no data found"
exception is hidden by the Oracle OCI library.

Thanks Tim Graham for the review and Jani Tiainen for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28859#comment:10>

Django

unread,
Apr 28, 2018, 1:40:29 PM4/28/18
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: oracle | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by GitHub <noreply@…>):

In [changeset:"483cc1c430e038d7d16342f76761d18b989c3eed" 483cc1c4]:
{{{
#!CommitTicketReference repository=""
revision="483cc1c430e038d7d16342f76761d18b989c3eed"
Refs #28859 -- Fixed "no data found" exception handling with cx_Oracle
6.3+.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28859#comment:11>

Django

unread,
Feb 4, 2019, 10:32:12 AM2/4/19
to django-...@googlegroups.com
#28859: Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle
backend.
-------------------------------------+-------------------------------------

Reporter: Jani Tiainen | Owner: felixxm
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: oracle | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by GitHub <noreply@…>):

In [changeset:"85f924a9b92f5922376c1d3f1a4f1af1d957ef0e" 85f924a9]:
{{{
#!CommitTicketReference repository=""
revision="85f924a9b92f5922376c1d3f1a4f1af1d957ef0e"
Refs #28859 -- Simplified fetch_returned_insert_id() by using int data
type for binding variable on Oracle.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28859#comment:12>

Reply all
Reply to author
Forward
0 new messages