Re: [Django] #12529: manage.py syncdb doesn't check tables by using mangled names with Oracle backend

35 views
Skip to first unread message

Django

unread,
Jul 31, 2011, 6:15:23 PM7/31/11
to django-...@googlegroups.com
#12529: manage.py syncdb doesn't check tables by using mangled names with Oracle
backend
-------------------------------------+-------------------------------------
Reporter: jtiai | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Database layer
Version: SVN | (models, ORM)
Resolution: | Severity: Normal
Triage Stage: Accepted | Keywords: syncdb oracle
Needs documentation: 0 | inspectdb
Patch needs improvement: 0 | Has patch: 0
UI/UX: 0 | Needs tests: 0
| Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by ramiro):

* keywords: syncdb oracle => syncdb oracle inspectdb
* ui_ux: => 0
* easy: => 0


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

Django

unread,
Feb 7, 2014, 6:22:59 AM2/7/14
to django-...@googlegroups.com
#12529: manage.py syncdb doesn't check tables by using mangled names with Oracle
backend
-------------------------------------+-------------------------------------
Reporter: jtiai | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master

(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: syncdb oracle | Needs documentation: 0
inspectdb | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by manelclos@…):

Hi, I've fixed this by changing django.db.backends.oracle.introspection.py

from:
{{{

def table_name_converter(self, name):
"Table name comparison is case insensitive under Oracle"
return name.lower()
}}}

to:
{{{
from django.db.backends import util
}}}

{{{
def table_name_converter(self, name):
"Table name comparison is case insensitive under Oracle"
max_length = self.connection.ops.max_name_length()
truncated = util.truncate_name(name.upper(), max_length)
return truncated.lower()
}}}

Is there any problem in this solution?

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

Django

unread,
Jun 7, 2014, 11:21:14 AM6/7/14
to django-...@googlegroups.com
#12529: manage.py syncdb doesn't check tables by using mangled names with Oracle
backend
-------------------------------------+-------------------------------------
Reporter: jtiai | Owner: nobody
Type: Bug | Status: closed

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

Severity: Normal | Triage Stage: Accepted
Keywords: syncdb oracle | Needs documentation: 0
inspectdb | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

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


Comment:

With the introduction of the new migrations framework in Django 1.7, this
issue doesn't exist anymore.

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

Django

unread,
Nov 20, 2014, 6:14:30 AM11/20/14
to django-...@googlegroups.com
#12529: manage.py syncdb doesn't check tables by using mangled names with Oracle
backend
-------------------------------------+-------------------------------------
Reporter: jtiai | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: fixed
Severity: Normal | Triage Stage: Accepted
Keywords: syncdb oracle | Needs documentation: 0
inspectdb | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by manelclos):

Hi, I can still reproduce this using Django 1.7 and 1.7.1.

As an example, let's use django-cas' table
"django_cas_session_service_ticket". This also happens with
easy_thumbails' table "easy_thumbnails_thumbnaildimensions".

The flow is like this:
- migrate command is called, eventually migrate.py:model_installed() is
called:

{{{
def model_installed(model):
opts = model._meta
converter = connection.introspection.table_name_converter
# Note that if a model is unmanaged we short-circuit and
never try to install it
return not ((converter(opts.db_table) in tables) or
(opts.auto_created and
converter(opts.auto_created._meta.db_table) in tables))
}}}

- here, the table name converter will just return name.lower(), which is
clearly NOT the name that was used to create the table.
- at creation time, the Oracle DatabaseOperations (oracle/base.py) class
will truncate the name:

{{{
def quote_name(self, name):
# SQL92 requires delimited (quoted) names to be case-sensitive.
When
# not quoted, Oracle has case-insensitive behavior for
identifiers, but
# always defaults to uppercase.
# We simplify things by making Oracle identifiers always
uppercase.
if not name.startswith('"') and not name.endswith('"'):
name = '"%s"' % backend_utils.truncate_name(name.upper(),
self.max_name_length())
# Oracle puts the query text into a (query % args) construct, so %
signs
# in names need to be escaped. The '%%' will be collapsed back to
'%' at
# that stage so we aren't really making the name longer here.
name = name.replace('%', '%%')
return name.upper()
}}}

- the check for table existance "(converter(opts.db_table) in tables)"
will fail, as tables array contains "django_cas_session_service1144" and
not "django_cas_session_service_ticket"

- with these changes in oracle/introspection.py everything works as
expected. imports included in function for easier testing:

{{{
def table_name_converter(self, name):
"Table name comparison is case insensitive under Oracle"

from django.db.backends import utils as backend_utils
from django.db.backends.oracle.base import DatabaseOperations
self.ops = DatabaseOperations(self)
name = backend_utils.truncate_name(name.upper(),
self.ops.max_name_length())
return name.lower()
}}}

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

Django

unread,
Nov 20, 2014, 7:00:25 AM11/20/14
to django-...@googlegroups.com
#12529: manage.py syncdb doesn't check tables by using mangled names with Oracle
backend
-------------------------------------+-------------------------------------
Reporter: jtiai | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: syncdb oracle | Needs documentation: 0
inspectdb | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by manelclos):

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


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

Django

unread,
Oct 24, 2025, 12:52:24 PM10/24/25
to django-...@googlegroups.com
#12529: manage.py syncdb doesn't check tables by using mangled names with Oracle
backend
-------------------------------------+-------------------------------------
Reporter: Jani Tiainen | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: syncdb oracle | Triage Stage: Accepted
inspectdb |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1
* owner: nobody => Mariusz Felisiak
* status: new => assigned

Comment:

[https://github.com/django/django/pull/19999 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/12529#comment:11>
Reply all
Reply to author
Forward
0 new messages