Skip to content

Index() throws an AttributeError when called with an object using declarative base #1214

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Anonymous

Currently, Index() can't be called with an object using the declarative layer. The result is:

AttributeError: 'InstrumentedAttribute' object has no attribute 'table'

However, using the columns directly works fine, but looks a bit ugly:

Index('viewforum', Topic.__table__.c.forum_id,
      Topic.__table__.c.sticky, Topic.__table__.c.last_post_id)

Many thanks,[BR]
Christoph (aka tux21b)

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Dec 21, 2008

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • added labels: high priority
  • set milestone to "0.5.0"
sqlalchemy-bot

sqlalchemy-bot commented on Jan 3, 2009

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

though this is problematic; if you say Index('foo', MyClass.foo), its going to force compilation of MyClass' mapper, which can cause problems if dependent classes and tables have not yet been defined. We might further want Index to defer getting the list of columns until create() is called, but then if your mapping has problems, you're going to have ORM errors within metadata.create_all() which is pretty nasty.

So it might be nice to get change the frigging _CompileOnAttr nastiness to be more of a complete InstrumentedAttribute at mapper construction time. A quick workaround would be to put a working __clause_element__() method on _CompileOnAttr.

sqlalchemy-bot

sqlalchemy-bot commented on Jan 3, 2009

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.5.0" to "0.5.xx"
sqlalchemy-bot

sqlalchemy-bot commented on Jan 5, 2009

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

(original author: ged)

sqlalchemy-bot

sqlalchemy-bot commented on Jan 11, 2009

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

implemented in 209e888.

sqlalchemy-bot

sqlalchemy-bot commented on Jan 11, 2009

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
added this to the 0.5.xx milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          Index() throws an AttributeError when called with an object using declarative base · Issue #1214 · sqlalchemy/sqlalchemy