home / django_tickets / tickets

tickets: 4499

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
4499 2007-06-07 08:45:28 2012-04-30 12:37:32 2022-03-06 03:31:37.190845 Accepted closed Database layer (models, ORM) Bug Normal dev fixed integrity error silently failing with postgres and loaddata 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. nobody sandro@e-den.it save integrity operationalError 0 0 0 0 0 0
Powered by Datasette · Queries took 1.134ms