Opened 6 years ago

Closed 6 years ago

Last modified 6 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:

Oracle9i Enterprise Edition Release - Production       
PL/SQL Release - Production                            
CORE	Production                                          
TNS for Linux: Version - Production                    
NLSRTL Version - 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:
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/ in decodestring, line 321
Python Executable:	/usr/bin/python2
Python Version:	2.7.3
Python Path:	
Server time:	Thu, 17 May 2012 22:17:39 -0600

Attachments (1)

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

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by Anssi Kääriäinen

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

comment:2 Changed 6 years ago by Ramiro Morales

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

Changed 6 years ago by eatkin@…

Attachment: oracle_corruption.tgz added

sample app demonstrating bug

comment:3 Changed 6 years ago by anonymous

Resolution: needsinfo
Status: closedreopened

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

I ran startproject oracle_corruption

and made the following modifications.

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

I then run

./manage runserver

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
  • 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:


Request Method: GET
Request URL:

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
Installed Middleware:

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


comment:4 Changed 6 years ago by Anssi Kääriäinen

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 Changed 6 years ago by anonymous

I'm using Oracle9i Enterprise Edition Release - 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).


comment:6 Changed 6 years ago by Anssi Kääriäinen

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