Hi all,
I'm trying to pin down what I think is a bug in Model.delete(), but
I'm encountering bizarre behaviour with my tests that I can't
reproduce in normal circumstances. In particular, it is as if
foreign key constraint checking has been turned off.
The attached patch adds tests that can be run with:
./tests/runtests.py --settings=your.settings.module delete
Currently the tests pass, but they shouldn't -- the DELETE statement
should produce an IntegrityError or OperationalError (or, if 'ON
DELETE CASCADE' was set then the subsequent queries should return
nothing). If I try similar things outside the test harness, I get
the exceptions I expect.
I'm testing this using a Postgres database, I've also tested with
sqlite and get the same thing, I haven't tested with MySQL.
Can anyone else confirm what I'm seeing? It is very bizarre. Does
anyone know if the test harness does something unusual with
constraints?
Cheers,
Luke
--
"I am going to let you move around more, just to break up the
mahogany." (True Quotes From Induhviduals, Scott Adams)
Luke Plant || http://lukeplant.me.uk/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: tests/modeltests/delete/__init__.py
===================================================================
--- tests/modeltests/delete/__init__.py (revision 0)
+++ tests/modeltests/delete/__init__.py (revision 0)
@@ -0,0 +1 @@
+
Property changes on: tests/modeltests/delete/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Index: tests/modeltests/delete/models.py
===================================================================
--- tests/modeltests/delete/models.py (revision 0)
+++ tests/modeltests/delete/models.py (revision 0)
@@ -0,0 +1,59 @@
+# coding: utf-8
+"""
+Tests for some corner cases with deleting.
+"""
+
+from django.db import models
+
+class DefaultRepr(object):
+ def __repr__(self):
+ return u"<%s: %s>" % (self.__class__.__name__, self.__dict__)
+
+class Member(DefaultRepr, models.Model):
+ name = models.CharField(max_length=100)
+
+class Poll(DefaultRepr, models.Model):
+ created_by = models.ForeignKey(Member, related_name="polls_created")
+
+class PollOption(DefaultRepr, models.Model):
+ text = models.CharField(max_length=100)
+ poll = models.ForeignKey(Poll, related_name="poll_options")
+
+class VoteInfo(DefaultRepr, models.Model):
+ poll_option = models.ForeignKey(PollOption, related_name="votes")
+ member = models.ForeignKey(Member, related_name="poll_votes")
+
+
+__test__ = {'API_TESTS': """
+>>> from django.db.models import sql
+>>> from django.db import connection
+>>> m = Member(name="joe")
+>>> m.save()
+>>> p = Poll(created_by=m)
+>>> p.save()
+>>> po = PollOption(text="An option", poll=p)
+>>> po.save()
+>>> vi = VoteInfo(poll_option=po, member=m)
+>>> vi.save()
+
+# This should fail:
+>>> c = connection.cursor()
+>>> c.execute("DELETE FROM delete_member;", [])
+
+>>> # Alternative can be done like this:
+>>> #q = sql.DeleteQuery(Member, connection)
+>>> #q.delete_batch([m.id])
+
+# Why doesn't the above fail? Are constraints turned off or something?
+# From the below, it would seem they are:
+
+>>> Poll.objects.all()
+[<Poll: {'created_by_id': 1, 'id': 1}>]
+>>> Member.objects.all()
+[]
+
+# The thing I really want to test:
+# m.delete()
+
+"""
+}
Property changes on: tests/modeltests/delete/models.py
___________________________________________________________________
Name: svn:eol-style
+ native