unit tests: malformed fixtures in test.orm
(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'),
),
Cheers!
Comments (6)
-
Account Deleted -
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 ?
-
repo owner oh right and check for no rows, I see the empty insert still occurs.
-
repo owner 0895e34d21c9818ec73e5c87e35ad6ba5c05acbd
fed2bd8ff0aaa938259b36b81f4993c74685d4e4
thanks for the tip !
-
Account Deleted (original author: fweber) Hi there, thanks for the fix! I'm trying to get the IBM DB2 dialect at http://code.google.com/p/ibm-db/source/browse/#svn/branches/ibm_db_sa up-to-date so it passes the unittests, and the DB2 driver throws an error for
INSERT INTO table ()
. I guess the better solution would be to make the dialect handle empty inserts without dying though. I'll look into that ;-) -
repo owner - removed milestone
Removing milestone: 0.7.9 (automated comment)
- Log in to comment
(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 forrows[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 fornodes
, its value was['p', 'd': 'a'}, {'i': 'd', 'd': 'a'}]({'i':)
. So I fixed thenodes
tuple above, but also had to add therows[table](table)
check:Sorry for the confusion!