Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#18339 closed Bug (worksforme)

The session db backend throws UnicodeEncodeError when used with Oracle

Reported by: eatkin@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords: oracle unicode corruption
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 Ramiro Morales)

I am experiencing the same symptoms as Ticket #9935, but the supposedly fixed cx_oracle 5.1.1 doesn't resolve this issue. Neither does backdating to 4.4.1 or 4.2.1 (I tested all those). I'm running django 1.4. I ported directly over from a mysql backend that was working great. What else could be useful?

Here is my oracle version:

BANNER                                                         
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production       
PL/SQL Release 9.2.0.6.0 - Production                            
CORE	9.2.0.6.0	Production                                          
TNS for Linux: Version 9.2.0.6.0 - Production                    
NLSRTL Version 9.2.0.6.0 - Production                            

and the django error page:

UnicodeEncodeError at /provisioning/nid_list
'ascii' codec can't encode characters in position 0-295: ordinal not in range(128)
Request Method:	GET
Request URL:	http://10.250.255.6:8000/provisioning/nid_list
Django Version:	1.4
Exception Type:	UnicodeEncodeError
Exception Value:	
'ascii' codec can't encode characters in position 0-295: ordinal not in range(128)
Exception Location:	/usr/lib/python2.7/base64.py in decodestring, line 321
Python Executable:	/usr/bin/python2
Python Version:	2.7.3
Python Path:	
['/home/eatkin/django/utopia',
 '/usr/lib/python27.zip',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info']
Server time:	Thu, 17 May 2012 22:17:39 -0600

Attachments (1)

oracle_corruption.tgz (4.8 KB ) - added by eatkin@… 12 years ago.
sample app demonstrating bug

Download all attachments as: .zip

Change History (7)

comment:1 by Anssi Kääriäinen, 12 years ago

Could you provide example code, and the full stack trace?

comment:2 by Ramiro Morales, 12 years ago

Description: modified (diff)
Resolution: needsinfo
Severity: Release blockerNormal
Status: newclosed

by eatkin@…, 12 years ago

Attachment: oracle_corruption.tgz added

sample app demonstrating bug

comment:3 by anonymous, 12 years ago

Resolution: needsinfo
Status: closedreopened

Sorry it took so long. I've made a very simple webapp that demonstrates the issue.

I ran

 django-admin.py startproject oracle_corruption

and made the following modifications.

  • edited settings.py to configure DATABASES for my connection
  • commented out USE_TZ from settings.py as it was causing another error (django.db.utils.DatabaseError: ORA-01882: timezone region not found)
  • created views.py with one view, test
  • edited urls.py to map to test view

I then run

./manage runserver 0.0.0.0:8000

and load /test. I get the error after only 5-6 refreshes. It will usually make it to 320 then croak. If I initialize the session to something len() > 0, it'll happen after just 2 or 3 reloads.

I'm running the following components:

  • Arch linux with this kernel 'Linux django 3.4.5-1-ARCH #1 SMP PREEMPT Mon Jul 16 21:35:54 CEST 2012 x86_64 GNU/Linux'
  • Python 2.7.3
  • instantclient-basic-linux.x64-11.2.0.3.0.zip
  • instantclient-sdk-linux.x64-11.2.0.3.0.zip
  • instantclient-sqlplus-linux.x64-11.2.0.3.0.zip
  • cx_Oracle-5.1.2.tar.gz (though I've tried 5.1.1, 4.4.1, and 4.2.1)

Here is the traceback:

Environment:


Request Method: GET
Request URL: http://10.250.255.6:8000/test

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/eatkin/django/oracle_corruption/oracle_corruption/views.py" in test
  5.         if 'data' not in request.session:
File "/usr/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in __contains__
  36.         return key in self._session
File "/usr/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  165.                 self._session_cache = self.load()
File "/usr/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load
  21.             return self.decode(force_unicode(s.session_data))
File "/usr/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in decode
  84.         encoded_data = base64.decodestring(session_data)
File "/usr/lib/python2.7/base64.py" in decodestring
  321.     return binascii.a2b_base64(s)

Exception Type: UnicodeEncodeError at /test
Exception Value: 'ascii' codec can't encode characters in position 0-256: ordinal not in range(128)

Thank you for your help and let me know if there is further information I can provide.

Eric

comment:4 by Anssi Kääriäinen, 12 years ago

Resolution: worksforme
Status: reopenedclosed

I can't reproduce this.

I tried both stable/1.4.x and master. no failures. I am using Python 2.7.3, Oracle 11G, cx_Oracle 5.1.1.

1.3 is in security fixes only mode, so that is out of scope.

Closing as worksforme.

comment:5 by anonymous, 12 years ago

I'm using Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production

I worked around this by changing the DJANGO_SESSION.SESSION_DATA column to CLOB from NCLOB. So, that works for me, but I thought I'd document the issue that's apparently particular to 9.2 or perhaps my configuration (I'm no Oracle DBA).

Eric

comment:6 by Anssi Kääriäinen, 12 years ago

So, maybe this is Oracle 9 specific problem. But, I don't have Oracle 9 available, so I can't confirm this.

If we want to add a documentation note about this then we need to know what exactly is causing the problem.

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