Re: problem with connection.commit

Federico Di Gregorio <fog-NGVKUo/i/[email protected]> Sat, 20 Feb 2010 23:39:57 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On 20/02/2010 14:53, [email protected] wrote:
> 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

I don't know if this problem is specific to Mac OS X but on my Linux
everything works as expected:

>>> c.execute("insert into table2 values (1)")
>>> o.commit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
psycopg2.IntegrityError: insert or update on table "table2" violates
foreign key constraint "table2_id_fkey"
DETAIL:  Key (id)=(1) is not present in table "table1".

Can someone with a Mac check the code and confirm this is a bug?

federico

-- 
Federico Di Gregorio                                       fog-NGVKUo/i/[email protected]
 La mia nuova versione del mondo prevede una consapevolezza
  distribuita e insapore.                             -- sisterconfusion

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkuAZMYACgkQvcCgrgZGjesHKQCgzXjyoowIVHIJQtpmyiAceluQ
rt4AoJ7n/eo22pCifhpQhgxdFL7aBu/N
=fkMX
-----END PGP SIGNATURE-----