Code

Opened 2 years ago

Closed 23 months ago

Last modified 23 months ago

#18085 closed Bug (worksforme)

sqllite integer is signed but django recognize as unsigned

Reported by: robotr Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: tutorial
Cc: m.r.sopacua@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When making "Writing your first Django app, part 2", I recieve this below:

IntegrityError at /admin/

column username is not unique

Request Method: 	POST
Request URL: 	http://127.0.0.1:8000/admin/
Django Version: 	1.4
Exception Type: 	IntegrityError
Exception Value: 	

column username is not unique

Exception Location: 	D:\Python2.7.3\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable: 	D:\Python2.7.3\python.exe
Python Version: 	2.7.3
Python Path: 	

['',
 'D:\\studio\\mysite',
 'D:\\studio',
 'C:\\Windows\\system32\\python27.zip',
 'D:\\Python2.7.3\\DLLs',
 'D:\\Python2.7.3\\lib',
 'D:\\Python2.7.3\\lib\\plat-win',
 'D:\\Python2.7.3\\lib\\lib-tk',
 'D:\\Python2.7.3',
 'D:\\Python2.7.3\\lib\\site-packages']

Server time: 	Sun, 8 Apr 2012 23:12:11 +0800

the superuser id is "1", but as django said is "4294967296"
my superuser can not login.

Attachments (0)

Change History (4)

comment:1 Changed 2 years ago by apollo13

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

Hi, can you provide more info? Especially a traceback would be helpful

comment:2 Changed 2 years ago by vincent.desprez@…

  • Resolution needsinfo deleted
  • Status changed from closed to reopened
  • Type changed from Uncategorized to Bug

Hello, same error. Here is my traceback.

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.4.1
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',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.flatpages')
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',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in wrapper
  213.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in inner
  195.                 return self.login(request)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in login
  326.         return login(request, **defaults)
File "C:\Python27\lib\site-packages\django\views\decorators\debug.py" in sensitive_post_parameters_wrapper
  69.             return view(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\auth\views.py" in login
  49.             auth_login(request, form.get_user())
File "C:\Python27\lib\site-packages\django\contrib\auth\__init__.py" in login
  76.     user_logged_in.send(sender=user.__class__, request=request, user=user)
File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py" in send
  172.             response = receiver(signal=self, sender=sender, **named)
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py" in update_last_login
  26.     user.save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  463.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save_base
  551.                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in _insert
  203.         return insert_query(self.model, objs, fields, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in insert_query
  1576.     return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  910.             cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\util.py" in execute
  40.             return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  337.             return Database.Cursor.execute(self, query, params)

Exception Type: IntegrityError at /admin/
Exception Value: column username is not unique

Thx

comment:3 Changed 23 months ago by msopacua

  • Cc m.r.sopacua@… added
  • Component changed from Uncategorized to Documentation
  • Keywords tutorial added
  • Resolution set to worksforme
  • Status changed from reopened to closed

I don't see how the traceback relates to your bug description. The SQL error points to the username field, which is a character field and your bug report mentions signed/unsigned issues with a numeric field. Many of us have gone through the tutorial without issues so try to figure out what you have done differently or at the very least explain how you came to the conclusion that above traceback is caused by a signedness issue.

comment:4 Changed 23 months ago by kmtracey

That's a very puzzling traceback. What it shows happening is Django auth code logging a user in (auth_login(request, form.get_user())), which causes the user logged in signal to fire (user_logged_in.send(sender=user.__class__, request=request, user=user)), which has a receiver in the auth models file (update_last_login) that sets the user's last login time to now and saves the user. Now things start to get weird. The Django ORM level code, instead of taking the path of saving an existing User model instance, takes the path of inserting a new row into the auth_user table. This path would ordinarily only be taken if the User instance primary key value was not set, but it must be set since the User model was retrieved from the DB earlier, and would not have been cleared by anything shown as installed in the system (full traceback is showing only Django code installed). At any rate this "new" user has an identical username to an existing user (likely the one logging in!) so the DB raises an integrity error.

This is two people now reporting this exception on what looks to be some version of Windows, Django 1.4.1, and Python 2.7.3. However I cannot recreate it on my Windows7/Django1.4.1/Python2.7.3 machine. The original report mentions 'the superuser id is "1", but as django said is "4294967296" my superuser can not login' but does not give any details of where that 42.. number was seen. It is a special number:

>>> hex(4294967296)
'0x100000000L'
>>>

1 in the high 32-bits of a 64-bit number, 0 in the low 32 bits, but how a 1 would get to be stored that way isn't clear to me. My best guess is there is some 32-bit vs. 64-bit incompatibility in the underlying Python/sqlite libraries installed. FWIW in my working setup I've got 64-bit Python installed on 64-bit Windows.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.