1. Michael Bayer
  2. sqlalchemy
  3. Issues


Issue #2573 resolved

unit tests: malformed fixtures in test.orm

Anonymous created an issue

(original reporter: fweber) Hi there,

while fiddling with the SQLAlchemy 0.7.8 unit tests, I noticed that the fixtures for test.orm are creating a malformed INSERT query (in this case, an empty INSERT query INSERT INTO nodes () VALUES ()) for the nodes table. The reason for this seems to be a missing comma in test/orm/_fixtures.py:L235:

            nodes = (
                    ('id', 'parent_id', 'data')

If I understand correctly, nodes should be a tuple with the header tuple as the first element, followed by a tuple for every row that should be inserted. Since there are no rows here, nodes should be a 1-tuple containing only the header tuple, but in fact, it's the header tuple itself, which leads to wrong results. So this should be (thanks to Python's paren rules):

            nodes = (
                    ('id', 'parent_id', 'data'),


Comments (6)

  1. Anonymous

    (original author: fweber) Oops, that's actually only one half of the bug. My initial fix for the problem with INSERT INTO nodes () VALUES () was to add a check for rows[table](table) in test.lib.fixtures:TableTest._load_fixtures to avoid empty inserts, but due to the missing comma mentioned above, rows[table](table) wasn't empty for nodes, its value was ['p', 'd': 'a'}, {'i': 'd', 'd': 'a'}]({'i':). So I fixed the nodes tuple above, but also had to add the rows[table](table) check:

                if rows[table](table):
                        [dict(zip(headers[table](dict(zip(headers[table), column_values))
                         for column_values in rows[table](table)])

    Sorry for the confusion!

  2. Michael Bayer repo owner

    Well, yes that line seems incorrect. To date there's been no symptom caused by it - an empty insert often has a special compilation form which we support, you'd see on SQLite for example it comes out as "INSERT INTO nodes DEFAULT VALUES".

    Easy enough to add a comma there though curious what platform are you testing where this actually caused something to fail ?

  3. Log in to comment