occasional integrity errors when mirroring groups

65 views
Skip to first unread message

Dario Vinella

unread,
Jan 7, 2013, 8:29:37 AM1/7/13
to django-a...@googlegroups.com
Hi,
I'm experiencing some integrity error exceptions on my site, powered by django 1.4.3 and updated
versions of django-auth-ldap. This happens rarely, a couple of times every month (with a couple hundreds
unique users per day).
My django-ldap-auth settings include AUTH_LDAP_MIRROR_GROUPS = True

Could these exceptions be related to django-auth-ldap or to django itself?

You could find the traceback below.

regards
Dario

---

Traceback (most recent call last):

[...]

  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/__init__.py", line 45, in authenticate
    user = backend.authenticate(**credentials)
  File "/usr/local/lib/python2.6/dist-packages/django_auth_ldap/backend.py", line 113, in authenticate
    user = ldap_user.authenticate(password)
  File "/usr/local/lib/python2.6/dist-packages/django_auth_ldap/backend.py", line 262, in authenticate
    self._get_or_create_user()
  File "/usr/local/lib/python2.6/dist-packages/django_auth_ldap/backend.py", line 479, in _get_or_create_user
    self._mirror_groups()
  File "/usr/local/lib/python2.6/dist-packages/django_auth_ldap/backend.py", line 577, in _mirror_groups
    self._user.groups = groups
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 834, in __set__
    manager.add(*value)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 578, in add
    self._add_items(self.source_field_name, self.target_field_name, *objs)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 663, in _add_items
    for obj_id in new_ids
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 419, in bulk_create
    self._batched_insert(objs_without_pk, fields, batch_size)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 868, in _batched_insert
    using=self.db)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 1593, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 910, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)

IntegrityError: duplicate key value violates unique constraint "auth_user_groups_user_id_group_id_key"
DETAIL:  Key (user_id, group_id)=(596, 1) already exists.

Peter Sagerson

unread,
Jan 8, 2013, 12:08:08 AM1/8/13
to django-a...@googlegroups.com
I was going to suggest that this might happen if the user was a member of multiple LDAP groups with the same common name, in which case the new set of groups could contain duplicates. However, I see (empirically as well as in the code) that Django helpfully de-dupes objects when adding to a many-to-many relation. The only thing I can think of is that you're seeing a race condition when one account is logging in multiple times simultaneously. Perhaps the odd double-click on a login button. Are you using TransactionMiddleware or otherwise wrapping the login view in a transaction? Assigning to any m2m in autocommit mode could certainly exhibit this.

Dario Vinella

unread,
Jan 8, 2013, 6:15:15 AM1/8/13
to django-a...@googlegroups.com
Currently all my ldap groups have different cns and i use the standard django.contrib.auth.views.login without any kind of customization (also I'm not using the transaction middleware at all). I'll try disabling the login button after the first click with some js and see if it helps.

thanks
Dario

Di majo

unread,
May 12, 2024, 2:01:47 PM5/12/24
to django-auth-ldap
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638

Reply all
Reply to author
Forward
0 new messages