﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4499	integrity error silently failing with postgres and loaddata	sandro@…	nobody	"

this is a simple example where a Model.save() that should raise
integrity/operational errors is not:
== example ==
{{{
#!python
class one(models.Model):
    fk_field = models.ForeignKey('two')

class two(models.Model):
    description = models.CharField(maxlength=10)
}}}
{{{
#!python
In [1]: from webfi.sd.models import *

In [2]: One(fk_field_id=1)
Out[2]: <One: One object>
In [3]: One(fk_field_id=1).save()
}}}
== pg logs ==
The last line should have raised an integrity error but it does not. Db log
(PostgreSQL) shows:

STATEMENT:  INSERT INTO ""sd_one"" (""fk_field_id"") VALUES (1)
2007-06-05 16:55:38 [30666] LOG:  duration: 0.345 ms  statement: SELECT CURRVAL('""sd_one_id_seq""')
STATEMENT:  SELECT CURRVAL('""sd_one_id_seq""')
2007-06-05 16:55:38 [30666] ERROR:  insert or update on table ""sd_one"" violates foreign key constraint ""$1""
DETAIL:  Key (fk_field_id)=(1) is not present in table ""sd_two"".

== a second save ==
a second 'save' results in:
{{{
In [4]: One(fk_field_id=1).save()
---------------------------------------------------------------------------
psycopg2.OperationalError                          Traceback (most recent call last)

/home/sandro/src/fossati/webfi/<ipython console>

/misc/src/django/trunk/django/db/models/base.py in save(self)
    241                 cursor.execute(""INSERT INTO %s (%s) VALUES (%s)"" % \
    242                     (backend.quote_name(self._meta.db_table), ','.join(field_names),
--> 243                     ','.join(placeholders)), db_values)
    244             else:
    245                 # Create a new record with defaults for everything.

/misc/src/django/trunk/django/db/backends/util.py in execute(self, sql, params)
     10         start = time()
     11         try:
---> 12             return self.cursor.execute(sql, params)
     13         finally:
     14             stop = time()

OperationalError:   insert or update on table ""sd_one"" violates foreign key constraint ""$1""
DETAIL:  Key (fk_field_id)=(1) is not present in table ""sd_two"".
}}}

And that's ok, but too late...

It seems to me too big a mistake so I hope I'm just missing something, if
not I'll file a new ticket for this. I think in no way a db error should be
ignored...

I tried with a fresh svn co of rel 5427.

"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	save integrity  operationalError	kbussell@… znick	Accepted	0	0	0	0	0	0
