Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

#11886 closed defect (fixed)

BaseException.message has been deprecated as of Python 2.6

Reported by: Jun Omae Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.5
Component: general Version: 1.0-stable
Severity: minor Keywords: exception
Cc: Branch:
Release Notes:

Fixed DeprecationWarning with Python 2.6 when creating an HTTPException from a PermissionError due to use of deprecated message attribute of base Exception class.

API Changes:
  • Added message property to PermissionError class.
  • Deprecated msg attribute of PermissionError class.
  • HTTPException is explicitly defined as an abstract base class.
Internal Changes:

Description

If non-TRAC_ADMIN user requests with hdfdump=1 parameter and Python 2.6 is used, Python says DeprecationWarning.

python trac/web/standalone.py  -p 3000 -a '*,/home/jun66j5/src/trac-htdigest.txt,auth'  /dev/shm/testenv
Server starting in PID 19162.
Serving on 0.0.0.0:3000 view at http://127.0.0.1:3000/
Using HTTP/1.1 protocol version
/home/jun66j5/src/tracdev/git/trac/web/api.py:137: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  self.detail = detail.message
192.168.11.11 - - [19/Dec/2014 13:03:40] "GET /testenv?hdfdump=1 HTTP/1.1" 403 -
192.168.11.11 - - [19/Dec/2014 13:03:40] "GET /testenv/chrome/site/your_project_logo.png HTTP/1.1" 404 -
192.168.11.11 - - [19/Dec/2014 13:03:40] "GET /testenv/chrome/site/your_project_logo.png HTTP/1.1" 404 -

Attachments (0)

Change History (13)

comment:1 by Ryan J Ollos, 6 years ago

Some of the comments in #11286 might be applicable.

comment:2 by Ryan J Ollos, 6 years ago

While working on #11286 I remember seeing the following behavior: DeprecationWarning with Python 2.6, but not with Python 2.7.

(py2.6)user@ubuntu:~/Workspace/t11944$ python
Python 2.6.9 (default, Jan 25 2014, 21:02:08) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> e = Exception("the message")
>>> e.message
__main__:1: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
'the message'
>>> dir(e)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', 'args', 'message']
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> e = Exception("the exception")
>>> e.message
'the exception'
>>> dir(e)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', 'args', 'message']

I thought I had found an explanation for that somewhere on Stack Overflow, but I'm unable to find it now. Anyway, PEP:0352 claims the message attribute was removed in Python 3.0, and I can confirm it is gone at least in 3.4.

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> e = Exception("the exception")
>>> dir(e)
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', 'args', 'with_traceback']

So it seems good to remove the message property from the TracError class for consistency. I did some work on that last weekend while I was offline that I'll post here soon for review.

in reply to:  2 comment:3 by Ryan J Ollos, 6 years ago

Replying to rjollos:

So it seems good to remove the message property from the TracError class for consistency. I did some work on that last weekend while I was offline that I'll post here soon for review.

Proposed changes in log:rjollos.git:t11886.

comment:4 by Ryan J Ollos, 6 years ago

Keywords: exception added
Milestone: next-stable-1.0.x1.0.4
Owner: set to Ryan J Ollos
Status: newassigned

in reply to:  description comment:5 by Ryan J Ollos, 6 years ago

Replying to jomae:

If non-TRAC_ADMIN user requests with hdfdump=1 parameter and Python 2.6 is used, Python says DeprecationWarning.

It looks like that's probably a PermissionError. Another way to avoid the deprecation warning would be to define the message property like the TracError class: tags/trac-1.0.2/trac/core.py@:48-49#L30.

The Error class in ConfigParser.py has the following code:

# exception classes
class Error(Exception):
    """Base class for ConfigParser exceptions."""

    def _get_message(self):
        """Getter for 'message'; needed only to override deprecation in
        BaseException."""
        return self.__message

    def _set_message(self, value):
        """Setter for 'message'; needed only to override deprecation in
        BaseException."""
        self.__message = value

    # BaseException.message has been deprecated since Python 2.6.  To prevent
    # DeprecationWarning from popping up over this pre-existing attribute, use
    # a new property that takes lookup precedence.
    message = property(_get_message, _set_message)

In light of those hints, I may rework the proposed changes.

comment:6 by Ryan J Ollos, 6 years ago

It seems to come down to:

  1. Deprecate message property of TracError and HTTPException and remove uses of message in the codebase.

or

  1. Add message property to the PermissionError class.

I'm slightly in favor of (1), for consistency with the BaseException class in Python 3. Any suggestions?

Last edited 6 years ago by Ryan J Ollos (previous) (diff)

in reply to:  6 ; comment:7 by Jun Omae, 6 years ago

I'm slightly in favor of (1), for consistency with the BaseException class in Python 3. Any suggestions?

+1 for (2).

We could remove uses of message in Trac core. I think we should do. However, we cannot remove uses in all plugins. Therefore, I think we should add message property to prevent the warnings.

comment:8 by Ryan J Ollos, 6 years ago

Milestone: 1.0.41.0.5

in reply to:  7 ; comment:9 by Ryan J Ollos, 6 years ago

Replying to jomae:

We could remove uses of message in Trac core.

Done in [13749:13750].

I think we should do. However, we cannot remove uses in all plugins. Therefore, I think we should add message property to prevent the warnings.

Additional proposed changes in log:rjollos.git:t11886.2 and log:rjollos.git:t11886.2-trunk.

comment:10 by Ryan J Ollos, 6 years ago

OT: the variable name hdfdump might not make much sense now that ClearSilver is removed. Maybe we should add an alias, such as datadump? This came to mind while reading TracTroubleshooting#ClearsilversHDF.

in reply to:  9 comment:11 by Jun Omae, 6 years ago

Additional proposed changes in log:rjollos.git:t11886.2 and log:rjollos.git:t11886.2-trunk.

Looks good to me.

in reply to:  10 comment:12 by Jun Omae, 6 years ago

OT: the variable name hdfdump might not make much sense now that ClearSilver is removed. Maybe we should add an alias, such as datadump? This came to mind while reading TracTroubleshooting#ClearsilversHDF.

IMO, I'd like to leave with no changes. I don't think it would be good to add a magic token even if it makes much sense. If an alias is added, I like such as __datadump which it rarely conflicts with tokens from Trac core and other plugins.

comment:13 by Ryan J Ollos, 6 years ago

API Changes: modified (diff)
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [13769,13771], merged to trunk in [13770,13772,13774]. Additional change on trunk in [13773].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.