Discussion:
Backwards Incompatibility in logging module in 3.4?
Don Spaulding
2014-06-12 22:38:26 UTC
Permalink
Hi there,

I just started testing a project of mine on Python 3.4.0b1. I ran into a
change that broke compatibility with the logging module in 3.3.

The basic test is:

$ py34/bin/python -c 'import logging;
print(logging.getLevelName("debug".upper()))'
Level DEBUG

$ py33/bin/python -c 'import logging;
print(logging.getLevelName("debug".upper()))'
10

I quickly stumbled upon this webpage:

http://aazza.github.io/2014/05/31/testing-on-multiple-versions-of-Python/

Which led me to this ticket regarding the change:

http://bugs.python.org/issue18046

Is this a bug or an intentional break? If it's the latter, shouldn't this
at least be mentioned in the "What's new in Python 3.4" document? If it's
the former, should I file a bug?

Thanks,
Don
Nick Coghlan
2014-06-12 23:10:16 UTC
Permalink
Post by Don Spaulding
Hi there,
I just started testing a project of mine on Python 3.4.0b1. I ran into a
change that broke compatibility with the logging module in 3.3.
Post by Don Spaulding
$ py34/bin/python -c 'import logging;
print(logging.getLevelName("debug".upper()))'
Post by Don Spaulding
Level DEBUG
$ py33/bin/python -c 'import logging;
print(logging.getLevelName("debug".upper()))'
Post by Don Spaulding
10
http://aazza.github.io/2014/05/31/testing-on-multiple-versions-of-Python/
http://bugs.python.org/issue18046
Is this a bug or an intentional break? If it's the latter, shouldn't
this at least be mentioned in the "What's new in Python 3.4" document? If
it's the former, should I file a bug?

Yes, it sounds like a bug to me - there's no indication of an intent to
change behaviour with that cleanup patch.

Cheers,
Nick.
Post by Don Spaulding
Thanks,
Don
_______________________________________________
Python-Dev mailing list
https://mail.python.org/mailman/listinfo/python-dev
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
Victor Stinner
2014-06-12 23:45:13 UTC
Permalink
Hi,
Post by Don Spaulding
Is this a bug or an intentional break? If it's the latter, shouldn't this
at least be mentioned in the "What's new in Python 3.4" document?
IMO the change is intentional. The previous behaviour was not really expected.

Python 3.3 documentation is explicit: the result is a string and the
input paramter is an integer. logging.getLevelName("DEBUG") was more
an implementation

https://docs.python.org/3.3/library/logging.html#logging.getLevelName
"Returns the textual representation of logging level lvl. If the level
is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or
DEBUG then you get the corresponding string. If you have associated
levels with names using addLevelName() then the name you have
associated with lvl is returned. If a numeric value corresponding to
one of the defined levels is passed in, the corresponding string
representation is returned. Otherwise, the string ‘Level %s’ % lvl is
returned."

If your code uses something like
logger.setLevel(logging.getLevelName("DEBUG")), use directly
logger.setLevel("DEBUG").

This issue was fixed in OpenStack with this change:
https://review.openstack.org/#/c/94028/6/openstack/common/log.py,cm
https://review.openstack.org/#/c/94028/6

Victor
Don Spaulding
2014-06-13 19:11:31 UTC
Permalink
Post by Victor Stinner
Hi,
Post by Don Spaulding
Is this a bug or an intentional break? If it's the latter, shouldn't
this
Post by Don Spaulding
at least be mentioned in the "What's new in Python 3.4" document?
IMO the change is intentional. The previous behaviour was not really expected.
I agree that the change seems intentional. However, as Nick mentioned, the
ticket doesn't really discuss the repercussions of changing the output of
the function. As far as I can tell, this function has returned an int when
given a string since it was introduced in Python 2.3. I think it's
reasonable to call a function's behavior "expected" after 11 years in the
wild.
Post by Victor Stinner
Python 3.3 documentation is explicit: the result is a string and the
input paramter is an integer. logging.getLevelName("DEBUG") was more
an implementation
https://docs.python.org/3.3/library/logging.html#logging.getLevelName
"Returns the textual representation of logging level lvl. If the level
is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or
DEBUG then you get the corresponding string. If you have associated
levels with names using addLevelName() then the name you have
associated with lvl is returned. If a numeric value corresponding to
one of the defined levels is passed in, the corresponding string
representation is returned. Otherwise, the string ‘Level %s’ % lvl is
returned."
If your code uses something like
logger.setLevel(logging.getLevelName("DEBUG")), use directly
logger.setLevel("DEBUG").
https://review.openstack.org/#/c/94028/6/openstack/common/log.py,cm
https://review.openstack.org/#/c/94028/6
Victor
I appreciate the pointer to the OpenStack fix. I've actually already
worked around the issue in my project (although without much elegance, I'll
readily admit).

I opened up an issue on the tracker for this:
http://bugs.python.org/issue21752

I apologize if that was out of turn.
Nick Coghlan
2014-06-13 23:28:22 UTC
Permalink
http://bugs.python.org/issue21752
Post by Don Spaulding
I apologize if that was out of turn.
At the very least, there should be a note in the "porting to Python 3.4"
section of the What's New and a versionchanged note on the API docs, so a
docs bug report is appropriate to add those.

Cheers,
Nick.
Post by Don Spaulding
_______________________________________________
Python-Dev mailing list
https://mail.python.org/mailman/listinfo/python-dev
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
Loading...