Table.fullname should be dynamic

Issue #1873 resolved
Former user created an issue

This is trivial to work-around, but fullname on Table is only set in init. If the table is renamed, or schema is assigned later, fullname becomes incorrect.

Not a high priority, just would have been nice.

Comments (9)

  1. Mike Bayer repo owner

    assigning to name will also screw up the Table's position in the metadata. its an unusual use case and name should really not be mutable.

  2. Former user Account Deleted

    Unusual, agreed, but we have extended migrate and are able to accomplish some cool magic by reassigning column and table names. (Sqlalchemy has also helped us create views on legacy oracle databases that look and act like the eventual replacement tables on postgres, so neither the app nor sqlalchemy is aware of the difference.) So, feel free continue to treat name as not mutable, but for us I'd ask: please don't enforce that in the future.

    If you reply, please add kb at retailarchitects ( dot com) to cc: (if you don't object, allow guest/guest to add to cc: ?)

  3. Mike Bayer repo owner

    what do you want to happen in the MetaData when name is changed ? there's a dictionary there of table objects keyed to names. its not such a big deal to put "fullname" behind a descriptor since its not frequently used, but looking at the source it seems like an arbitrary place to put that. columns have derived names too, like the "key", also a "fullname", what about those ? there's basically a use case here and I'd like it to make sense.

  4. Former user Account Deleted

    I've worked around this issue by creating my own dictionary somewhat like this:

    tables = dict((table.full_name, table) for table in metadata.tables.values())
    

    I've added a full_name property (note underscore) to Table when I am migrating the database: (For my purposes, I wanted these set as lowercase for comparison...)

    class UpgradeTable(object):
    
        @property
        def full_name(self):
            """
            fullname on sqlalchemy.schema.Table object is statically set at __init__
            we will provide full_name property
            """
            if self.schema:
                return ("%s.%s" % (self.schema, self.name)).lower()
            else:
                return self.name.lower()
    
    # add UpgradeTable as superclass to Table
    Table.__bases__ += (UpgradeTable, )
    
  5. Former user Account Deleted

    Replying to guest:

    I've worked around this issue by creating my own dictionary somewhat like this:

    tables = dict((table.full_name, table) for table in metadata.tables.values())
    

    Obviously, in my case, this is just another static "snap-shot" of the keys as the names currently are, but that was sufficient for my purposes.

  6. Former user Account Deleted

    Another comment: for my purposes, it is very nice that renaming Column.name leaves Column.key alone, because it tracks that information for me. (I could always write it to Column.info or add an attribute if you need to change it).

    Also, this isn't very pressing for us, at least, since I've worked around any issues I've had. It was more of a suggestion. My suspicion is, however, that I've got more use-cases for sqlalchemy than most other users, so it wouldn't surprise me if no-one else really needs this.

  7. Mike Bayer repo owner

    OK, well let me put this in the "icebox" for now, not like we wouldn't ever do it, but my long term goal from about a year or two ago and continuing is to remove all these little "ambiguous" corners from the public API. its a small thing sure but I would prefer if mutability of Table could be an all-or-nothing thing (with the "all" being quite a big job).

  8. Mike Bayer repo owner

    there's no action to take on this particular ticket and 'name' is remaining one of those "don't change that !" kind of things.

  9. Log in to comment