Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urllib2 maximum recursion depth exceeded #50749

Closed
nako521 mannequin opened this issue Jul 17, 2009 · 13 comments
Closed

urllib2 maximum recursion depth exceeded #50749

nako521 mannequin opened this issue Jul 17, 2009 · 13 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@nako521
Copy link
Mannequin

nako521 mannequin commented Jul 17, 2009

BPO 6500
Nosy @orsenthil, @ezio-melotti, @berkerpeksag, @serhiy-storchaka
Files
  • issue6500.diff
  • issue6500_2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-01-18.08:59:33.280>
    created_at = <Date 2009-07-17.08:26:12.551>
    labels = ['type-bug', 'library']
    title = 'urllib2 maximum recursion depth exceeded'
    updated_at = <Date 2016-01-18.08:59:33.278>
    user = 'https://bugs.python.org/nako521'

    bugs.python.org fields:

    activity = <Date 2016-01-18.08:59:33.278>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-01-18.08:59:33.280>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2009-07-17.08:26:12.551>
    creator = 'nako521'
    dependencies = []
    files = ['40112', '41510']
    hgrepos = []
    issue_num = 6500
    keywords = ['patch']
    message_count = 13.0
    messages = ['90612', '90615', '100258', '247916', '257373', '257566', '257569', '257572', '257573', '257575', '258495', '258504', '258506']
    nosy_count = 7.0
    nosy_names = ['jhylton', 'orsenthil', 'ezio.melotti', 'nako521', 'python-dev', 'berker.peksag', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6500'
    versions = ['Python 2.7']

    @nako521
    Copy link
    Mannequin Author

    nako521 mannequin commented Jul 17, 2009

    def __getattr__(self, attr):
            # XXX this is a fallback mechanism to guard against these
            # methods getting called in a non-standard order.  this may be
            # too complicated and/or unnecessary.
            # XXX should the __r_XXX attributes be public?
            if attr[:12] == '_Request__r_':
                name = attr[12:]
                if hasattr(Request, 'get_' + name):
                    getattr(self, 'get_' + name)()
                    return getattr(self, attr)
            raise AttributeError, attr

    this may cause "maximum recursion depth exceeded"

    >>> import urllib2
    >>> req = urllib2.Request('http://www.nbc.com')
    >>> req._Request__r_method
    RuntimeError: maximum recursion depth exceeded

    "return getattr(self, attr)"? should it be removed?

    @nako521 nako521 mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 17, 2009
    @ezio-melotti
    Copy link
    Member

    That __getattr__ was removed in r70815 and in Python 3.1 it's OK.
    The change wasn't backported to the trunk though.

    Assigning to Jeremy to see what he thinks about it.

    @jhylton
    Copy link
    Mannequin

    jhylton mannequin commented Mar 1, 2010

    Ok. I'll take a look, too.

    Jeremy

    On Sat, Feb 27, 2010 at 4:30 AM, Ezio Melotti <report@bugs.python.org> wrote:

    Changes by Ezio Melotti <ezio.melotti@gmail.com>:

    ----------
    nosy: +orsenthil
    status: pending -> open


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue6500\>


    @berkerpeksag
    Copy link
    Member

    Here is a patch for 2.7. I don't think backporting 9eceb618274a to 2.7 is worth the effort for this, so I just fixed the __getattr__ method and added a test.

    @berkerpeksag
    Copy link
    Member

    Thank you Ezio, I'll commit this tomorrow.

    @berkerpeksag berkerpeksag assigned berkerpeksag and unassigned jhylton Jan 2, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 6, 2016

    New changeset fbea8ff8db5e by Berker Peksag in branch '2.7':
    Issue bpo-6500: Fix "maximum recursion depth exceeded" error caused by Request.__getattr__()
    https://hg.python.org/cpython/rev/fbea8ff8db5e

    @orsenthil
    Copy link
    Member

    Hi @berker,

    This patch breaks the unit tests. Could you confirm (or reject) this?
    Thanks

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 6, 2016

    New changeset e2faa18802bb by Berker Peksag in branch '2.7':
    Issue bpo-6500: Reverting fbea8ff8db5e since it broke tests
    https://hg.python.org/cpython/rev/e2faa18802bb

    @berkerpeksag
    Copy link
    Member

    Thanks, Senthil. I've just reverted fbea8ff8db5e. Sorry for the noise!

    @berkerpeksag berkerpeksag reopened this Jan 6, 2016
    @serhiy-storchaka
    Copy link
    Member

    __getattr__() was purposed to handle two lazily created private attributes: __r_type and __r_host. They are set in corresponding get_-methods.

    Here is a patch that makes __getattr__() to handle only these attributes.

    @orsenthil
    Copy link
    Member

    @serhiy, the patch looks good to me. This change is an excellent idea. Please commit it.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 18, 2016

    New changeset d34fdd1736f2 by Serhiy Storchaka in branch '2.7':
    Issue bpo-6500: Fixed infinite recursion in urllib2.Request.__getattr__().
    https://hg.python.org/cpython/rev/d34fdd1736f2

    @serhiy-storchaka
    Copy link
    Member

    Thank you for the review Senthil.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants