Ticket #19354: 19354-1.diff

File 19354-1.diff, 7.1 KB (added by claudep, 3 years ago)

Do not assume user.id == user.pk

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 64d71fe..1597d3c 100644
    a b class ModelAdmin(BaseModelAdmin): 
    552552        """
    553553        from django.contrib.admin.models import LogEntry, DELETION
    554554        LogEntry.objects.log_action(
    555             user_id         = request.user.id,
     555            user_id         = request.user.pk,
    556556            content_type_id = ContentType.objects.get_for_model(self.model).pk,
    557557            object_id       = object.pk,
    558558            object_repr     = object_repr,
  • django/contrib/auth/__init__.py

    diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py
    index 5dbda44..99348d3 100644
    a b def login(request, user): 
    8484        user = request.user
    8585    # TODO: It would be nice to support different login methods, like signed cookies.
    8686    if SESSION_KEY in request.session:
    87         if request.session[SESSION_KEY] != user.id:
     87        if request.session[SESSION_KEY] != user.pk:
    8888            # To avoid reusing another user's session, create a new, empty
    8989            # session if the existing session corresponds to a different
    9090            # authenticated user.
    9191            request.session.flush()
    9292    else:
    9393        request.session.cycle_key()
    94     request.session[SESSION_KEY] = user.id
     94    request.session[SESSION_KEY] = user.pk
    9595    request.session[BACKEND_SESSION_KEY] = user.backend
    9696    if hasattr(request, 'user'):
    9797        request.user = user
  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index 9279c52..10d9eca 100644
    a b class PasswordResetForm(forms.Form): 
    241241                'email': user.email,
    242242                'domain': domain,
    243243                'site_name': site_name,
    244                 'uid': int_to_base36(user.id),
     244                'uid': int_to_base36(user.pk),
    245245                'user': user,
    246246                'token': token_generator.make_token(user),
    247247                'protocol': use_https and 'https' or 'http',
  • django/contrib/auth/tests/templates/context_processors/auth_attrs_user.html

    diff --git a/django/contrib/auth/tests/templates/context_processors/auth_attrs_user.html b/django/contrib/auth/tests/templates/context_processors/auth_attrs_user.html
    index aa7f784..dc4c6b1 100644
    a b  
    11unicode: {{ user }}
    2 id: {{ user.id }}
     2id: {{ user.pk }}
    33username: {{ user.username }}
    44url: {% url 'userpage' user %}
  • django/contrib/auth/tokens.py

    diff --git a/django/contrib/auth/tokens.py b/django/contrib/auth/tokens.py
    index 930c700..6e5bfe7 100644
    a b class PasswordResetTokenGenerator(object): 
    5858        # Ensure results are consistent across DB backends
    5959        login_timestamp = user.last_login.replace(microsecond=0, tzinfo=None)
    6060
    61         value = (six.text_type(user.id) + user.password +
     61        value = (six.text_type(user.pk) + user.password +
    6262                six.text_type(login_timestamp) + six.text_type(timestamp))
    6363        hash = salted_hmac(key_salt, value).hexdigest()[::2]
    6464        return "%s-%s" % (ts_b36, hash)
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index d27e2f5..2562a63 100644
    a b def password_reset_confirm(request, uidb36=None, token=None, 
    206206        post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete')
    207207    try:
    208208        uid_int = base36_to_int(uidb36)
    209         user = UserModel.objects.get(id=uid_int)
     209        user = UserModel.objects.get(pk=uid_int)
    210210    except (ValueError, OverflowError, UserModel.DoesNotExist):
    211211        user = None
    212212
  • docs/ref/templates/builtins.txt

    diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
    index ba43e2e..0098037 100644
    a b Output the contents of the block if the two arguments equal each other. 
    618618
    619619Example::
    620620
    621     {% ifequal user.id comment.user_id %}
     621    {% ifequal user.pk comment.user_id %}
    622622        ...
    623623    {% endifequal %}
    624624
  • tests/regressiontests/model_formsets_regress/tests.py

    diff --git a/tests/regressiontests/model_formsets_regress/tests.py b/tests/regressiontests/model_formsets_regress/tests.py
    index 1fbdb97..8cadcfc 100644
    a b class FormfieldShouldDeleteFormTests(TestCase): 
    351351
    352352        def should_delete(self):
    353353            """ delete form if odd PK """
    354             return self.instance.id % 2 != 0
     354            return self.instance.pk % 2 != 0
    355355
    356356    NormalFormset = modelformset_factory(User, form=CustomDeleteUserForm, can_delete=True)
    357357    DeleteFormset = modelformset_factory(User, form=CustomDeleteUserForm, formset=BaseCustomDeleteModelFormSet)
    class FormfieldShouldDeleteFormTests(TestCase): 
    392392        data = dict(self.data)
    393393        data['form-INITIAL_FORMS'] = 4
    394394        data.update(dict(
    395             ('form-%d-id' % i, user.id)
     395            ('form-%d-id' % i, user.pk)
    396396            for i,user in enumerate(User.objects.all())
    397397        ))
    398398        formset = self.NormalFormset(data, queryset=User.objects.all())
    class FormfieldShouldDeleteFormTests(TestCase): 
    409409        data = dict(self.data)
    410410        data['form-INITIAL_FORMS'] = 4
    411411        data.update(dict(
    412             ('form-%d-id' % i, user.id)
     412            ('form-%d-id' % i, user.pk)
    413413            for i,user in enumerate(User.objects.all())
    414414        ))
    415415        data.update(self.delete_all_ids)
    class FormfieldShouldDeleteFormTests(TestCase): 
    428428        data = dict(self.data)
    429429        data['form-INITIAL_FORMS'] = 4
    430430        data.update(dict(
    431             ('form-%d-id' % i, user.id)
     431            ('form-%d-id' % i, user.pk)
    432432            for i,user in enumerate(User.objects.all())
    433433        ))
    434434        data.update(self.delete_all_ids)
    class FormfieldShouldDeleteFormTests(TestCase): 
    440440        self.assertEqual(len(User.objects.all()), 2)
    441441
    442442        # verify no "odd" PKs left
    443         odd_ids = [user.id for user in User.objects.all() if user.id % 2]
     443        odd_ids = [user.pk for user in User.objects.all() if user.pk % 2]
    444444        self.assertEqual(len(odd_ids), 0)
  • tests/regressiontests/transactions_regress/tests.py

    diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py
    index 66e0477..5d1ab2c 100644
    a b class TestTransactionClosing(TransactionTestCase): 
    140140            "Create a user in a transaction"
    141141            user = User.objects.create_user(username='system', password='iamr00t', email='root@SITENAME.com')
    142142            # Redundant, just makes sure the user id was read back from DB
    143             Mod.objects.create(fld=user.id)
     143            Mod.objects.create(fld=user.pk)
    144144
    145145        # Create a user
    146146        create_system_user()
Back to Top