django session InvalidOperation

60 views
Skip to first unread message

kinder

unread,
Dec 8, 2010, 7:49:26 PM12/8/10
to Django users
I'm fairly new to Django, and I'm trying to move an existing Django
application to a new server. The old server is running Django 1.0.2
and Python 2.5.4. The closest I could come on my new server (to start)
is Django 1.0.4 and Python 2.5.5.

Anyway, I get an admin login screen, but when I try to log in, I get
an error:

Exception Type: InvalidOperation
Exception Value: Invalid literal for Decimal: '2010-12-22 17:36:30'
Exception Location: build/bdist.linux-i686/egg/MySQLdb/connections.py
in defaulterrorhandler, line 35

If I'm reading the error page right, it looks like it's happening in
db/models/query.py, somewhere around here:

316. clone = self.filter(*args, **kwargs)
317. num = len(clone) ...

Any advice on how to get past this?

Dan Fairs

unread,
Dec 9, 2010, 2:22:21 PM12/9/10
to django...@googlegroups.com
Hi there,

You'll need to post a longer stack trace, just a fragment isn't much use. Switch to the copy-and-paste view so you can copy-and-paste it :)

Cheers,
Dan
--
Dan Fairs | dan....@gmail.com | www.fezconsulting.com


kinder

unread,
Dec 9, 2010, 6:18:46 PM12/9/10
to Django users
Hi Dan,

Thanks for taking a look... here's the copy-and-paste stack trace.

======

Environment:

Request Method: POST
Request URL: http://sitename.com/admin/
Django Version: 1.0.4
Python Version: 2.5.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.flatpages',
'django.contrib.admin',
'django_extensions',
'analytics',
'attachments',
'contact',
'dashboard',
'donate',
'filebrowser',
'minicontent',
'news',
'pagination',
'partners',
'social_aggregator',
'tagging',
'news_video',
'utils',
'volunteers']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'pagination.middleware.PaginationMiddleware')


Traceback:
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/
base.py" in get_response
91. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/local/lib/python2.5/site-packages/django/contrib/admin/
sites.py" in root
141. if not self.has_permission(request):
File "/usr/local/lib/python2.5/site-packages/django/contrib/admin/
sites.py" in has_permission
100. return request.user.is_authenticated() and
request.user.is_staff
File "/usr/local/lib/python2.5/site-packages/django/contrib/auth/
middleware.py" in __get__
5. request._cached_user = get_user(request)
File "/usr/local/lib/python2.5/site-packages/django/contrib/auth/
__init__.py" in get_user
83. user_id = request.session[SESSION_KEY]
File "/usr/local/lib/python2.5/site-packages/django/contrib/sessions/
backends/base.py" in __getitem__
46. return self._session[key]
File "/usr/local/lib/python2.5/site-packages/django/contrib/sessions/
backends/base.py" in _get_session
172. self._session_cache = self.load()
File "/usr/local/lib/python2.5/site-packages/django/contrib/sessions/
backends/db.py" in load
16. expire_date__gt=datetime.datetime.now()
File "/usr/local/lib/python2.5/site-packages/django/db/models/
manager.py" in get
117. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.5/site-packages/django/db/models/
query.py" in get
317. num = len(clone)
File "/usr/local/lib/python2.5/site-packages/django/db/models/
query.py" in __len__
173. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.5/site-packages/django/db/models/
query.py" in iterator
288. for row in self.query.results_iter():
File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/
query.py" in results_iter
205. for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/
query.py" in execute_sql
1820. cursor.execute(sql, params)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/
util.py" in execute
19. return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/mysql/
base.py" in execute
83. return self.cursor.execute(query, args)
File "build/bdist.linux-i686/egg/MySQLdb/cursors.py" in execute
166. self.errorhandler(self, exc, value)
File "build/bdist.linux-i686/egg/MySQLdb/connections.py" in
defaulterrorhandler
35. raise errorclass, errorvalue

Exception Type: InvalidOperation at /admin/
Exception Value: Invalid literal for Decimal: '2010-12-23 16:53:08'

satyandra babu

unread,
Dec 9, 2010, 6:31:00 PM12/9/10
to django...@googlegroups.com
Hi,

for using MySQl with python MySQLdb and it will work fine :)

enjoy coding.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


kinder

unread,
Dec 9, 2010, 7:28:06 PM12/9/10
to Django users
Ummm... did you mean to say something before the 'for using'? Should I
not use MySQLdb (I'm using version 1.2.2)?

satyandra babu

unread,
Dec 9, 2010, 7:34:34 PM12/9/10
to django...@googlegroups.com
MySQLdb is required to use MySQL with python, so but the error is same as check to import mysqldb if it working fine, i hope the issue is somewhere mysqldb settings only.

kinder

unread,
Dec 10, 2010, 9:33:09 AM12/10/10
to Django users
At least superficially, it looks like MySQLDB is working ok - a row
does end up inserted in the django_session table. The reason I am
looking in /usr/local/lib/python2.5/site-packages/django/db/models/
query.py around line 317 is because (according to the interactive
stack trace) that is where the local variable 'clone' takes on the
value "Error in formatting: Invalid literal for Decimal: '2010-12-24
08:25:03'"

I'm hoping this is some kind of database configuration/model-mismatch
problem, or maybe... (the "old" server MySQL version is 5.0.77, the
new, 5.1.47)

Any other ideas?

kinder

unread,
Dec 10, 2010, 10:38:26 AM12/10/10
to Django users
After some more futzing around this morning, I'm thinking this might
be a shared library version mismatch, maybe with the MySQL client
shared libraries? How can I find out what version django/python is
using?

kinder

unread,
Dec 10, 2010, 10:31:19 PM12/10/10
to Django users
I'm stumped... even removing mod_php from the apache config (which is
where I suspected a different mysql shared library), I still get the
same InvalidOperation error. Any suggestions what to try next?

Leo

unread,
Dec 11, 2010, 10:18:06 AM12/11/10
to Django users
Hard to know from what's shown here, but it seems likely that your
database didn't get created properly on the new server. The error
suggests that the expire_date column of the django_session table in
the MySQL database is of type DECIMAL rather than the expected
DATETIME. How did you migrate the database to the new server? It's
best to use mysqldump and not simply copy the data files when you're
changing MySQL versions.

Ignacio

unread,
Dec 22, 2010, 4:32:14 PM12/22/10
to Django users
Hi kinder. I've got this exact problem with django 1.2.3 and python
2.7.
Could you find a fix for it?

kinder

unread,
Jan 16, 2011, 12:39:17 PM1/16/11
to Django users
Unfortunately, no, I could not find a fix for it.

I still suspect some kind of version conflict in the MySQL drivers,
but it's strange, because I even tried creating a new test app, and
django created the database and all the tables just fine. It's only
the admin login that seems to break it.

But in my case, I didn't/couldn't recompile the mysql client libraries
because I'm running other production applications on the same box. I
ended up redeploying the app on a different webhost (webfaction) that
specifically supports Django, and it works fine there.

Let us know if you can find a solution.
Reply all
Reply to author
Forward
0 new messages