problem with connection.commit

[email protected] Sat, 20 Feb 2010 14:53:33 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Hi all,

I am new to this mailing list so I appreciate that this might be a
noobie kind of question.
I have some problems with connection object commit behavior.

Let's say we have the following tables in the db:

create table table1 (id integer primary key);
create table table2 (id integer references table1(id) deferrable
initially deferred);

Now, I am running this python code:

    import psycopg2
    conn = psycopg2.connect(...)

    cursor = conn.cursor()
    cursor.execute("insert into table2 values (1)")
    conn.commit() # Does not throw an exception

    cursor2 = conn.cursor()
    cursor2.execute("select * from table2") # Throws OperationalError:
insert or update on table "table2" violates foreign key constraint
"table2_id_fkey" DETAIL: Key (id)=(1) is not present in table
"table1".

So the question is why the conn.commit call doesn't throw an exception?
Is it a bug or am I missing something?
I am using psycopg2 2.0.13 with PostgreSQL 8.3.5 on Mac OS X 10.5.6

Thanks a lot!
Vitali