#28859 closed Bug (fixed)
Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle backend.
| Reported by: | Jani Tiainen | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | oracle |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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'
Attachments (2)
Change History (14)
by , 8 years ago
| Attachment: | django-oracle-bug.tar.gz added |
|---|
by , 8 years ago
| Attachment: | 28859.diff added |
|---|
comment:1 by , 8 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
| Version: | 1.11 → 2.0 |
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.
follow-up: 4 comment:2 by , 8 years ago
| Summary: | Django hides exception from database with Oracle backend. → Django hides NO_DATA_FOUND exception from database with Oracle backend. |
|---|
comment:3 by , 8 years ago
Other exceptions e.g. DUP_VAL_ON_INDEX, ZERO_DIVIDE, TOO_MANY_ROWS are raised properly.
follow-up: 5 comment:4 by , 8 years ago
Replying to 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'
comment:5 by , 8 years ago
Replying to 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.
comment:6 by , 8 years ago
| Has patch: | set |
|---|---|
| Summary: | Django hides NO_DATA_FOUND exception from database with Oracle backend. → Oracle OCI library hides NO_DATA_FOUND exception from database with Oracle backend. |
comment:7 by , 8 years ago
I added workaround in the Oracle back-end, since issue will not be fixed in the Oracle OCI library (see comment).
comment:8 by , 8 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:9 by , 8 years ago
| Version: | 2.0 → master |
|---|
Minimal project to demonstrate the problem