Hi Tony,

On Fri, 2009-01-09 at 03:29 -0800, Tony wrote:
> This is the reference: (not sure if I interpreted it right - sorry,
> newb :)
> 
> "If you use a multiple-table UPDATE  statement involving InnoDB tables
> for which there are foreign key constraints, the MySQL optimizer might
> process tables in an order that differs from that of their parent/
> child relationship. In this case, the statement fails and rolls back.
> Instead, update a single table and rely on the ON UPDATE capabilities
> that InnoDB provides to cause the other tables to be modified
> accordingly. See Section 13.5.5.4, “FOREIGN KEY Constraints”."

Django doesn't do any multi-table updates. They're a custom feature in
MySQL and it wasn't really worth adding lots of extra code to exploit
that feature in the relatively rare cases it could be used. I think you
can rule that out as the cause of your problem.

I must admit I haven't really looked at this problem report very much,
beyond reading it and thinking there wasn't anything that was
*obviously* wrong (so it's something that's subtle). Since you've
managed to have a problem in the Model.delete() code and are using
MySQL, you've hit two of my personal least favourite aspects in the ORM
and I've unfortunately prioritised accordingly (I have a number of
unpleasant Django things to work on, but some of them are just slightly
less unpleasant than this one).

To offer some assistance, though: if this was something I was seeing,
I'd reach for the debugging print statements to try and see what we were
telling the database. It's a little tricky to print out the SQL that is
executed for delete statements, since you can't do the normal trick of
printing "queryset.query.as_sql()", as delete() works immediately and
doesn't return a queryset. However, look in
django.db.models.sql.subqueries.DeleteQuery.do_query(). Just before the
call to self.execute_sql(), you could print out self.as_sql() to see
what we're trying to do for each call. That might provide some clues.

You might also want to have a read through bug titles in the "database"
component in Trac to see if any of them look similar to yours. I know
there are a couple of delete-related ones in there.

One day I hope to work up the enthusiasm to really attack Model.delete()
with enthusiasm. It appears to be a little fragile in unpredictable ways
(no obvious bugs, but people keep tripping over things and whether it's
a code error on their part or a Django ORM error, the error messages are
lots of not-fun to interpret).  Actually, what I'd really like is for
somebody else to attack Model.delete() with enthusiasm, but I'm not
holding my breath.

Regards,
Malcolm



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

Reply via email to