Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2494 (closed defect: fixed)

Opened 7 years ago

Last modified 7 years ago

DuplicateEntryError: column visit_key is not unique

Reported by: xaka Owned by: Chris Arndt
Priority: normal Milestone: 1.1.2
Component: Identity Version: 1.0.9
Severity: normal Keywords:
Cc:

Description

Details:
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/cherrypy/filters/__init__.py", line 151, in applyFilters
    method()
  File "/usr/lib/pymodules/python2.5/turbogears/visit/api.py", line 244, in before_main
    plugin.record_request(visit)
  File "/usr/lib/pymodules/python2.5/turbogears/identity/visitor.py", line 181, in record_request
    identity = self.identity_from_request(visit.key)
  File "/usr/lib/pymodules/python2.5/turbogears/identity/visitor.py", line 92, in identity_from_request
    identity = source(visit_key)
  File "/usr/lib/pymodules/python2.5/turbogears/identity/visitor.py", line 162, in identity_from_form
    identity = self.provider.validate_identity(user_name, pw, visit_key)
  File "/usr/lib/pymodules/python2.5/turbogears/identity/soprovider.py", line 261, in validate_identity
    return SqlObjectIdentity(visit_key, user)
  File "/usr/lib/pymodules/python2.5/turbogears/identity/soprovider.py", line 68, in __init__
    self.login()
  File "/usr/lib/pymodules/python2.5/turbogears/identity/soprovider.py", line 174, in login
    visit = visit_class(visit_key=self.visit_key, user_id=self._user.id)
  File "/usr/lib/python2.5/site-packages/sqlobject/main.py", line 1221, in __init__
    self._create(id, **kw)
  File "/usr/lib/python2.5/site-packages/sqlobject/main.py", line 1269, in _create
    self._SO_finishCreate(id)
  File "/usr/lib/python2.5/site-packages/sqlobject/main.py", line 1293, in _SO_finishCreate
    id, names, values)
  File "/usr/lib/python2.5/site-packages/sqlobject/dbconnection.py", line 710, in queryInsertID
    self._connection, soInstance, id, names, values)
  File "/usr/lib/python2.5/site-packages/sqlobject/sqlite/sqliteconnection.py", line 220, in _queryInsertID
    self._executeRetry(conn, c, q)
  File "/usr/lib/python2.5/site-packages/sqlobject/sqlite/sqliteconnection.py", line 190, in _executeRetry
    raise DuplicateEntryError(msg)
DuplicateEntryError: column visit_key is not unique

It happens very rarely when user trying to login via login form. Strange that self.visit_key returns None (i.e. self.visit_key not in table and we can create a new visit identity record), but when TG trying do that, DuplicateEntryError? exception raises. How it's possible? First call said "OK, you can add me", but second call said "Hey, i'm already in table".

I spent much time to investigate the reason, learned Visit and Identity code, but now i'm confused. Seems like a race condition somewhere, but where?

Change History

comment:1 Changed 7 years ago by chrisz

  • Milestone changed from __unclassified__ to 1.1.2

comment:2 Changed 7 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to fixed

Your analysis was correct, it's a reace condition that might occur if the database query is somewhat slow and an impatient user somehow manages to double-click the login button.

You can easily simulate this with a time.sleep(10) in the login method after getting the visit_link. The problem exists with both soprovider and saprovider, fixed both in r7174 now.

Note: See TracTickets for help on using tickets.