Code

Opened 4 years ago

Closed 4 years ago

#13653 closed (fixed)

Python 2.4 + hashlib causes AttributeError calling hmac.new()

Reported by: kmtracey Owned by: kmtracey
Component: Core (Other) Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If you install the standalone hashlib module on Python 2.4, attempting to do anything the admin that requires creation of a message results in an error:

Traceback (most recent call last):

  File "C:\u\kmt\django\trunk\django\core\servers\basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)

  File "C:\u\kmt\django\trunk\django\core\servers\basehttp.py", line 674, in __call__
    return self.application(environ, start_response)

  File "C:\u\kmt\django\trunk\django\core\handlers\wsgi.py", line 245, in __call__
    response = middleware_method(request, response)

  File "C:\u\kmt\django\trunk\django\contrib\messages\middleware.py", line 23, in process_response
    unstored_messages = request._messages.update(response)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\base.py", line 138, in update
    return self._store(messages, response)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\fallback.py", line 48, in _store
    remove_oldest=False)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\cookie.py", line 91, in _store
    encoded_data = self._encode(messages)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\cookie.py", line 128, in _encode
    return '%s$%s' % (self._hash(value), value)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\cookie.py", line 115, in _hash
    return hmac.new(key, value, sha_hmac).hexdigest()

  File "C:\bin\Python24\lib\hmac.py", line 107, in new
    return HMAC(key, msg, digestmod)

  File "C:\bin\Python24\lib\hmac.py", line 42, in __init__
    self.outer = digestmod.new()

AttributeError: 'builtin_function_or_method' object has no attribute 'new'

The django.utils.hashcompat module assumes that if hashlib imports without error, then the whole stdlib is 2.5. But when running on 2.4+standalone hashlib, we've got 2.4 hmac, and the sha_hmac value set in hashcompat needs to be the one for 2.4, not the value that works for 2.5+ and is set when the hashlib import succeeds.

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to kmtracey
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by kmtracey

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

(In [13310]) Fixed #13653: Fixed django.utils.hashcompat to support running on Python 2.4 with standalone hashlib.

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.