On Mon, 2007-02-26 at 17:19 +0000, Manoj Govindan wrote: > Hi Malcolm, > After reading your post, I added a couple of assertions. > 1) Check for subProject.parent immediately after creating the > subProject object. > 2) Compare id()s of project and subProject.parent *after saving* > subProject. > > The test now looks like this: > > class ProjectTests(unittest.TestCase): > def testCreateProjectAndSubProject(self): > project = Project(name = "aProject") > subProject = Project(name = "aSubProject", parent = project) > > self.assert_(subProject.parent) # Passes > > project.save() > self.assert_(project.id) # Passes > > subProject.save() > self.assertEqual(id(project), id(subProject.parent)) # Fails > > self.assert_(subProject.parent) # Fails > > The first new assertion worked, while the second failed. It seems > that something weird is happening somewhere inside Django. It would be > greatly appreciated if one (or more) of the developers could please > have a look at this and tell me if and where I am going wrong.
Something that is making this hard to debug is that you are not checking that certain values do not change. Try printing out the necessary values or compare directly for equality (remember, assert() only checks for "not false" and classes can evaluate to True even when they contain nothing in particular). I would like to see if subProject.parent the first time you test it (your first assert()) is exactly the same as after the subProject.save() line. Also are id(project) and id(subProject.parent) the same after you do the initial construction of the subProject class? If so, what is subProject.parent.id after the project.save() line? Is it equal to parent.id? In other words, to debug this, we need to establish a few things, in order: - did parent get assigned to subProject.parent in the first place? - if so, did it make a copy, or use a reference? - assuming both objects were the same at this point, does this fact ever change (particularly after subProject.save())? Once we know that something is true at point A and false at point B, we can decide it changed in between A and B. At the moment, we don't have that information. Don't be afraid to print things out for debugging purposes, or to save the value of parent.id and call failUnlessEqual() or assertEqual() to check the exact value in an automated test. Using plain assert() can sometimes lead to problems being disguised. If you could check these things out, I think we will be able to get a better idea of where the real problem is hiding. 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---