#72 Fix bug 1546294

closed-accepted
Oleg Broytman
None
5
2006-09-05
2006-08-24
No

Here is the patch that fixes bug 1546294.

Discussion

  • Patch to fix bug 1546294

     
    Attachments
  • Oleg Broytman
    Oleg Broytman
    2006-09-01

    Logged In: YES
    user_id=4799

    Please add a test or at least short test script that fails
    without the patch.

     
  • Oleg Broytman
    Oleg Broytman
    2006-09-01

    • assigned_to: nobody --> phd
     
  • Logged In: YES
    user_id=1583356

    OK, here's a test that fails with the exception

    psycopg2.ProgrammingError: invalid input syntax for type
    boolean: "c_id = (1)"

    It appears to work OK on sqlite (my other test platform)

     
  • Failing test

     
    Attachments
  • Oleg Broytman
    Oleg Broytman
    2006-09-04

    • status: open --> open-invalid
     
  • Oleg Broytman
    Oleg Broytman
    2006-09-04

    Logged In: YES
    user_id=4799

    I rewrote the test to the SQLObject test suite:

    from sqlobject import *
    from sqlobject.inheritance import *
    from sqlobject.tests.dbtest import *

    class TestCascade1(InheritableSQLObject):
    dummy=IntCol()

    class TestCascade2(TestCascade1):
    c=ForeignKey('TestCascade3', cascade='null')

    class TestCascade3(SQLObject):
    dummy=IntCol()

    def test_destroySelf():
    setupClass([TestCascade1, TestCascade3, TestCascade2])

    c = TestCascade3(dummy=1)
    b = TestCascade2(cID=c.id, dummy=1)
    c.destroySelf()
    print b

    and it works even without your patch. So the test is
    invalid. This is the debugging output:

    ============================= test process starts

    testing-mode: inprocess
    executable: /usr/local/bin/python (2.4.3-final-0)
    using py lib: /usr/local/src/Python/py-dist/py <rev unknown>

    testDestroyCascade.py[1] inserting into sys.path:
    /usr/local/src/Python/py-dist
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade2'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade2'

    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade3'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade3'

    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade1'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade1'

    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade2'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade2'

    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade3'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade3'

    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade1'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade1'

    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade1'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade1'

    1/COMMIT : auto
    1/Query : CREATE TABLE test_cascade1 (
    id SERIAL PRIMARY KEY,
    child_name VARCHAR(255),
    dummy INT
    )
    1/QueryR : CREATE TABLE test_cascade1 (
    id SERIAL PRIMARY KEY,
    child_name VARCHAR(255),
    dummy INT
    )
    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade3'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade3'

    1/COMMIT : auto
    1/Query : CREATE TABLE test_cascade3 (
    id SERIAL PRIMARY KEY,
    dummy INT
    )
    1/QueryR : CREATE TABLE test_cascade3 (
    id SERIAL PRIMARY KEY,
    dummy INT
    )
    1/COMMIT : auto
    1/QueryOne:
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade2'

    1/QueryR :
    SELECT COUNT(relname) FROM pg_class
    WHERE relname = 'test_cascade2'

    1/COMMIT : auto
    1/Query : CREATE TABLE test_cascade2 (
    id SERIAL PRIMARY KEY,
    child_name VARCHAR(255),
    c_id INT, CONSTRAINT c_id_exists FOREIGN KEY (c_id)
    REFERENCES test_cascade3 (id) ON DELETE SET NULL
    )
    1/QueryR : CREATE TABLE test_cascade2 (
    id SERIAL PRIMARY KEY,
    child_name VARCHAR(255),
    c_id INT, CONSTRAINT c_id_exists FOREIGN KEY (c_id)
    REFERENCES test_cascade3 (id) ON DELETE SET NULL
    )
    1/COMMIT : auto
    1/QueryIns: INSERT INTO test_cascade3 (id, dummy) VALUES
    (1, 1)
    1/COMMIT : auto
    1/QueryOne: SELECT dummy FROM test_cascade3 WHERE id = (1)
    1/QueryR : SELECT dummy FROM test_cascade3 WHERE id = (1)
    1/COMMIT : auto
    1/QueryIns: INSERT INTO test_cascade1 (id, dummy,
    child_name) VALUES (1, 1, NULL)
    1/COMMIT : auto
    1/QueryOne: SELECT child_name, dummy FROM test_cascade1
    WHERE id = (1)
    1/QueryR : SELECT child_name, dummy FROM test_cascade1
    WHERE id = (1)
    1/COMMIT : auto
    1/Query : UPDATE test_cascade1 SET child_name =
    ('TestCascade2') WHERE id = (1)
    1/QueryR : UPDATE test_cascade1 SET child_name =
    ('TestCascade2') WHERE id = (1)
    1/COMMIT : auto
    1/QueryIns: INSERT INTO test_cascade2 (id, child_name,
    c_id) VALUES (1, NULL, 1)
    1/COMMIT : auto
    1/QueryOne: SELECT child_name, c_id FROM test_cascade2.

    ================== tests finished: 1 passed in 0.28 seconds

    WHERE id = (1)
    1/QueryR : SELECT child_name, c_id FROM test_cascade2
    WHERE id = (1)
    1/COMMIT : auto
    1/Select : SELECT test_cascade2.id,
    test_cascade2.child_name, test_cascade2.c_id FROM
    test_cascade2 WHERE c_id = (1)
    1/QueryR : SELECT test_cascade2.id,
    test_cascade2.child_name, test_cascade2.c_id FROM
    test_cascade2 WHERE c_id = (1)
    1/COMMIT : auto
    1/Query : UPDATE test_cascade2 SET c_id = (NULL) WHERE
    id = (1)
    1/QueryR : UPDATE test_cascade2 SET c_id = (NULL) WHERE
    id = (1)
    1/COMMIT : auto
    1/Query : DELETE FROM test_cascade3 WHERE id = (1)
    1/QueryR : DELETE FROM test_cascade3 WHERE id = (1)
    1/COMMIT : auto
    <TestCascade2 1L cID=None dummy=1>

     
  • Logged In: YES
    user_id=1583356

    Given that the test which I attached fails, what is the next
    step to resolve this issue?

     
  • Oleg Broytman
    Oleg Broytman
    2006-09-04

    Logged In: YES
    user_id=4799

    I'dlike to wait until a clear test.

    You have reported that the test failed with

    psycopg2.ProgrammingError: invalid input syntax for type
    boolean: "c_id = (1)"

    But I don't see any boolean there. Are you sure you've
    submitted the same test that produced the error message?

    Your test works for me with python 2.3 and 2.4, with SQLite
    and Postgres 7.4, with PySQLite1 and PySQLite2, psycopg1 and
    psycopg2.

     
  • Logged In: YES
    user_id=1583356

    I'll give more detail when I get back to work tomorrow, but
    the "boolean" thing is simple to explain. The WHERE clause
    generated actually included the *quoted string* "c_id =
    (1)", as in
    SELECT blah FROM blah WHERE "c_id = (1)"
    The use of sqlbuilder in the patch prevents this weird
    quoting, and seems to be a better way of generating queries,
    anyway (by the DRY principle).

    Like I said, I can give you all the details of my
    installation tomorrow, but my recollection is that I'm using
    psycopg2, Python 2.4, Postgres 7.4 server, and (I believe) a
    Postgres 8.0 client.

     
  • Oleg Broytman
    Oleg Broytman
    2006-09-05

    Logged In: YES
    user_id=4799

    Now point you fingers and laugh at me! You test is ok - that
    is, without your patch it failed with exactly that error
    message. The problem was that I tested your patch with
    0.7-branch where it worked. With SQLObject from the trunk it
    failed, and your patch helps. Sorry for the confusion!

    The patch with the test is applied and committed in the
    revision 1901 to the trunk, rev. 1902 to the 0.7-branch.
    Thank you very much!

     
  • Oleg Broytman
    Oleg Broytman
    2006-09-05

    • status: open-invalid --> closed-accepted