Hi,

  i got a simple example where a Model.save() that should raise
  integrity/operational errors is not:

class one(models.Model):
    fk_field = models.ForeignKey('two')

class two(models.Model):
    description = models.CharField(maxlength=10)


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()
    
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' 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.

Any comments?

sandro
*:-)


-- 
Sandro Dentella  *:-)
e-mail: [EMAIL PROTECTED] 
http://www.tksql.org                    TkSQL Home page - My GPL work

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to