SQLCompiler's _truncated_identifier method may create truncated names that collide with untruncated names

Issue #3396 resolved
Chung Wu created an issue

Where label_length is 63, and current counter value is 12, the if I have a name that is 64 characters long, the truncated name will be the first 57 characters plus "c" (which is hex(12)[2:]). This would collide with a name that is 58 characters with the same 57-character prefix and ends in "c".

A possible fix is to truncate all names that are longer than label_length - 6, instead of just those that are longer than label_length.

Comments (4)

  1. Mike Bayer repo owner

    I suppose this is what you're talking about:

    from sqlalchemy import table, column, select
    from sqlalchemy import create_engine
    
    e = create_engine("sqlite://", echo=True, label_length=23)
    
    t = table("tablename", column('columnname_one'), column('columnn_1'))
    
    stmt = select([t]).apply_labels()
    
    compiled = stmt.compile(dialect=e.dialect)
    
    print(compiled)
    

    output:

    SELECT tablename.columnname_one AS tablename_columnn_1, tablename.columnn_1 AS tablename_columnn_1 
    FROM tablename
    
  2. Mike Bayer repo owner
    • Fixed bug where the truncation of long labels in SQL could produce a label that overlapped another label that is not truncated; this because the length threshhold for truncation was greater than the portion of the label that remains after truncation. These two values have now been made the same; label_length - 6. The effect here is that shorter column labels will be "truncated" where they would not have been truncated before. fixes #3396

    → <<cset ac52239b328f>>

  3. Log in to comment