FBDialect.reflecttable can raise an Assertion error on older firebird databases

Issue #1663 resolved
Former user created an issue

Versions of Firebird prior to 2.0 were subject to the following bug http://tracker.firebirdsql.org/browse/CORE-356

The gist of CORE-356 is that values in the RDB$DEFAULT_SOURCE column of the RDB$RELATION_FIELDS table can have leading whitespace.

Trying to use meta.reflect on one of these tables results in errors like this:

File ".../site-packages/sqlalchemy/databases/firebird.py", line 501, in reflecttable
    assert row['fdefault']('fdefault').upper().startswith('DEFAULT '), row
AssertionError: (u'ARCHIVED           ', None, u'TEXT', 0, 1, None, 0, " DEFAULT 'N'")

A simple fix for this is to add a TRIM to the tblqry around the COALESCE or since the fdefault value is being modified with .upper anyway line 501 might be a better spot to "fix" this

assert row['fdefault']('fdefault').upper().lstrip().startswith('DEFAULT '), row

Comments (10)

  1. Lele Gaifax

    Given that strip() considers CR and LF as whitespace, only the assertion seems wrong it that case, isn't it?

  2. Former user Account Deleted

    yes -- the assertion is wrong if 'DEFAULT' is followed by a newline.

    how about something like this:

    assert defexpr.startswith('DEFAULT') and defexpr[9](9) in string.whitespace, "Unrecognized default value: %s" % defexpr
    

    (note that this requires importing string, but at least it avoids re

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

    there is a typo in my previous comment. To avoid index errors the whitespace needs to be found at

    defexpr[7](7)
    

    not

    defexpr[9](9)
    

    I am going to reopen this since the assert will raise an Exception that client code will not be in a position to correct.

  4. Lele Gaifax

    I fixed the assertion on both branches (see 6699 and 6700). I even transposed the CORE-356 examples into a test case, even if the issue seems corrected in current firebirds...

    If you happen to be using a broken version, I'd be curious to know whether the test/dialect/test_firebird.py spot the problem.

  5. Log in to comment