brilliant, you are correct:
Foreign-key constraints:
"traffic_tracking2010_content_type_id_fkey" FOREIGN KEY
(content_type_id) REFERENCES django_content_type(id) DEFERRABLE
INITIALLY DEFERRED
"traffic_tracking2010_src_content_type_id_fkey" FOREIGN KEY
(src_content_type_id) REFERENCES django_content_type(id) DEFERRABLE
INITIALLY DEFERRED
"traffic_tracking2010_user_id_fkey" FOREIGN KEY (user_id)
REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
I wouldn't want to change that anyway.
Now what I still don't get is:
# doesn't protect against foreign key errors anyway ??
try:
sid = transaction.savepoint()
tracking.save()
transaction.savepoint_commit(sid)
except Exception,e:
get_logger().exception("tracking save: %s (%s)" % (src,e))
transaction.savepoint_rollback(sid)
why that attempt to commit just that save doesn't raise.
I really don't want to have to check for existence of User and
ContentType
thanks again.
as for why django didn't catch it:
http://code.djangoproject.com/ticket/12909
On Jun 13, 11:30 pm, akaariai <[email protected]> wrote:
> > Can anybody figure out why the IntegrityError doesn't get thrown till
> > then ?
> > Why didn't Django catch errors thrown in middleware ?
>
> Most likely the foreign keys are defined as "deferrable initially
> deferred", meaning that the database doesn't check them before commit.
> And this of course means that Django can't catch the error before
> commit.
>
> From the error message it seems like you are using Postgres, you can
> check if this is the case by running manage.py dbshell and then type
> "\d traffic_tracking2010". From the output you should see the
> deferrable initially deferred on the foreign key. You could manually
> disable the deferred behavior, but I don't know what this breaks.
> Probably something, as there must be some reason for Django using
> deferred checking.
>
> --
> Anssi
--
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.