Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#27977 closed Bug (wontfix)

inspectdb errors after upgrade to cx_Oracle 5.3

Reported by: JorisBenschop Owned by: nobody
Component: Database layer (models, ORM) Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by JorisBenschop)

Hi

After upgrading Oracle from 11.2 to 12.1 (which required updating cx_Oracle to 5.3 for some reason), {{manage.py inspectdb}} returns errors

# Unable to inspect table 'test_table'
# The error was: unorderable types: NoneType() > int()

My original install was 1.9, but upgrading to Django 1.10 gave the same error. Oddly, the error in 1.9 came with a complete stack trace, while the one in 1.10 only have the above error. Here's the stack from 1.9

from django.db import models
DEBUG (0.004) QUERY = "SELECT TABLE_NAME, 't' FROM USER_TABLES UNION ALL SELECT VIEW_NAME, 'v' FROM USER_VIEWS" - PARAMS = (); args=None


class AuthGroup(models.Model):
DEBUG (14.986) QUERY = '\n    SELECT ta.column_name, tb.table_name, tb.column_name\n    FROM   user_constraints, USER_CONS_COLUMNS ca, USER_CONS_COLUMNS cb,\n           user_tab_cols ta, user_tab_cols tb\n    WHERE  user_constraints.table_name = :arg0 AND\n           ta.table_name = user_constraints.table_name AND\n           ta.column_name = ca.column_name AND\n           ca.table_name = ta.table_name AND\n           user_constraints.constraint_name = ca.constraint_name AND\n           user_constraints.r_constraint_name = cb.constraint_name AND\n           cb.table_name = tb.table_name AND\n           cb.column_name = tb.column_name AND\n           ca.position = cb.position' - PARAMS = ('AUTH_GROUP',); args=['AUTH_GROUP']
DEBUG (8.362) QUERY = "\n    SELECT LOWER(uic1.column_name) AS column_name,\n           CASE user_constraints.constraint_type\n               WHEN 'P' THEN 1 ELSE 0\n           END AS is_primary_key,\n           CASE user_indexes.uniqueness\n               WHEN 'UNIQUE' THEN 1 ELSE 0\n           END AS is_unique\n    FROM   user_constraints, user_indexes, user_ind_columns uic1\n    WHERE  user_constraints.constraint_type (+) = 'P'\n      AND  user_constraints.index_name (+) = uic1.index_name\n      AND  user_indexes.uniqueness (+) = 'UNIQUE'\n      AND  user_indexes.index_name (+) = uic1.index_name\n      AND  uic1.table_name = UPPER(:arg0)\n      AND  uic1.column_position = 1\n      AND  NOT EXISTS (\n              SELECT 1\n              FROM   user_ind_columns uic2\n              WHERE  uic2.index_name = uic1.index_name\n                AND  uic2.column_position = 2\n           )\n        " - PARAMS = ('auth_group',); args=['auth_group']
Traceback (most recent call last):
  File "./manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/core/management/commands/inspectdb.py", line 25, in handle
    for line in self.handle_inspection(options):
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/core/management/commands/inspectdb.py", line 66, in handle_inspection
    indexes = connection.introspection.get_indexes(cursor, table_name)
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/db/backends/oracle/introspection.py", line 144, in get_indexes
    for row in cursor.fetchall():
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/db/utils.py", line 102, in inner
    return func(*args, **kwargs)
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/db/backends/oracle/base.py", line 519, in fetchall
    return tuple(_rowfactory(r, self.cursor) for r in self.cursor.fetchall())
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/db/backends/oracle/base.py", line 519, in <genexpr>
    return tuple(_rowfactory(r, self.cursor) for r in self.cursor.fetchall())
  File "/tools/general/app/anaconda-python-3.4/lib/python3.4/site-packages/django/db/backends/oracle/base.py", line 580, in _rowfactory
    elif precision > 0:
TypeError: unorderable types: NoneType() > int()

The default database only contains tables that django itself has made and that were not touched by any user directly.

Change History (5)

comment:1 by JorisBenschop, 7 years ago

    SELECT LOWER(uic1.column_name) AS column_name,
           CASE user_constraints.constraint_type
               WHEN 'P' THEN 1 ELSE 0
           END AS is_primary_key,
           CASE user_indexes.uniqueness
               WHEN 'UNIQUE' THEN 1 ELSE 0
           END AS is_unique
    FROM   user_constraints, user_indexes, user_ind_columns uic1
    WHERE  user_constraints.constraint_type (+) = 'P'
      AND  user_constraints.index_name (+) = uic1.index_name
      AND  user_indexes.uniqueness (+) = 'UNIQUE'
      AND  user_indexes.index_name (+) = uic1.index_name
      AND  uic1.table_name = UPPER(:arg0)
      AND  uic1.column_position = 1
      AND  NOT EXISTS (
              SELECT 1
              FROM   user_ind_columns uic2
              WHERE  uic2.index_name = uic1.index_name
                AND  uic2.column_position = 2
           )

cursor.bindvars
[<cx_Oracle.STRING with value 'auth_group'>]

cursor.description
[('COLUMN_NAME', <class 'cx_Oracle.STRING'>, 4000, 12000, None, None, 1), ('IS_PRIMARY_KEY', <class 'cx_Oracle.NUMBER'>, 127, None, None, None, 1), ('IS_UNIQUE', <class 'cx_Oracle.NUMBER'>, 127, None, None, None, 1)]

then in backends/oracle/base/_rowfactory the second item is processed ('IS_PRIMARY_KEY', <class 'cx_Oracle.NUMBER'>, 127, None, None, None, 1)

precision, scale = desc[4:6]
...
elif precision > 0

But the cursor.description coming from Oracle say that precision and scale are None, so we crash.

for completeness:

import cx_Oracle
cx_Oracle.__version__
'5.3'

hope this helps

comment:2 by JorisBenschop, 7 years ago

Description: modified (diff)
Summary: inspectdb errors after upgrade to Oracle 12.1inspectdb errors after upgrade to cx_Oracle 5.3

comment:3 by JorisBenschop, 7 years ago

downgrading to cx_Oracle 5.2 solves the issue. So this may be a problem in cx_Oracle instead?

comment:4 by Mariusz Felisiak, 7 years ago

Resolution: wontfix
Status: newclosed

Django 1.10 doesn't support cx_Oracle 5.3 and higher (see #27924). Please use cx_Oracle 5.2.1 instead.

in reply to:  4 comment:5 by JorisBenschop, 7 years ago

Replying to felixxm:

Django 1.10 doesn't support cx_Oracle 5.3 and higher (see #27924). Please use cx_Oracle 5.2.1 instead.

Apologies for submitting this duplicate ticket, and my gratitude for pointing me to this

Note: See TracTickets for help on using tickets.
Back to Top