I have a Django (version 1.5) application that is getting this Oracle error:
ORA-01461: can bind a LONG value only for insert into a LONG column
After doing some database debugging, it appears that the problem is caused by doing an INSERT on the DJANGO_SESSION table with a long (roughly 2.5k characters) Unicode string value for SESSION_DATA (data type NCLOB).
I have been told by a coworker that the problem does not occur on UPDATEs but only on INSERTs, because the Django database code for UPDATEs contains logic to (I'm paraphrasing here) split the database write into manageable chunks, but for some reason that logic is missing for INSERTs.
Armed with this information, I figured I could work around it by writing a small piece of custom middleware that does an immediate request.session.save() with a (presumably) empty value for SESSION_DATA and then later on when the session data is set, that would cause an UPDATE instead of an INSERT.
However, it appears not to be that simple. If I insert my custom middleware in settings.MIDDLEWARE_CLASSES above the entry for 'django.contrib.sessions.middleware.SessionMiddleware', the request object doesn't have the session attribute yet, and I get this error:
AttributeError: 'WSGIRequest' object has no attribute 'session'
And if I insert my middleware after the SessionMiddleware entry, it's too late in the process and I get the original ORA-01461 error.
So, is there a way to work around the ORA-01461 error using middleware? Or at all?