Alias._copy_internals raises AttributeError

Issue #1641 resolved
Former user created an issue

Found in 0.5.6, also appears to be present in trunk.

The implementation of the offending method includes::

baseselectable = baseselectable.selectable

which causes "AttributeError: 'Alias' object has no attribute 'selectable'" to be raised.

Looking at the implementation of __init__, shouldn't it be::

baseselectable = baseselectable.element

I only noticed this when I had aliases of aliases. Unfortunately, I was not able to make a small test case that exposes this issue, even with the aliases of aliases.

Comments (5)

  1. Mike Bayer repo owner

    sorry, what line of code are you looking at ? here is 0.5 branch:

     def __init__(self, selectable, alias=None):
            baseselectable = selectable
            while isinstance(baseselectable, Alias):
                baseselectable = baseselectable.element
            self.original = baseselectable
            self.supports_execution = baseselectable.supports_execution
            if self.supports_execution:
                self._autocommit = baseselectable._autocommit
            self.element = selectable
            if alias is None:
                if self.original.named_with_column:
                    alias = getattr(self.original, 'name', None)
                alias = _generated_label('%%(%d %s)s' % (id(self), alias or 'anon'))
            self.name = alias
    

    here is trunk:

        def __init__(self, selectable, alias=None):
            baseselectable = selectable
            while isinstance(baseselectable, Alias):
                baseselectable = baseselectable.element
            self.original = baseselectable
            self.supports_execution = baseselectable.supports_execution
            if self.supports_execution:
                self._autocommit = baseselectable._autocommit
            self.element = selectable
            if alias is None:
                if self.original.named_with_column:
                    alias = getattr(self.original, 'name', None)
                alias = _generated_label('%%(%d %s)s' % (id(self), alias or 'anon'))
            self.name = alias
    

    no access of baseselectable.selectable. that's from an old version of SQLA so I think you have some files mixed up.

  2. Former user Account Deleted
    • changed status to open
    • removed status

    Sorry for the misleading snippet: the line of code I'm looking at is in Alias._copy_internals (lines 2657-2659 in 0.5.6):

            baseselectable = self.element
            while isinstance(baseselectable, Alias):
                baseselectable = baseselectable.selectable
    

    When I referred to the __init__ method, I meant that it has similar code that works correctly (lines 2621-2623 in 0.5.6):

            baseselectable = selectable
            while isinstance(baseselectable, Alias):
                baseselectable = baseselectable.element
    

    So, it looks like Alias._copy_internals should use baseselectable.element instead of baseselectable.selectable in the while loop.

  3. Mike Bayer repo owner
    • changed milestone to 0.5.7

    OK, thanks. You'd probably get that issue in conjunction with query.join() or eagerloads - if you can send me a stack trace I can produce a test from that.

  4. Log in to comment