﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7419	Testing framework or model save behaves differently after qsrf merge (r7233/r7599)	peschler	nobody	"I'm currently facing a weird problem with the testing framework after
updating to the latest trunk version of the newforms-admin branch. I
have written a small example and a unittest to explain the issue and
to show that there seems to be some sort of problem after the qsrf
merge. I'm not quite sure where the problem is - unittest or qsrf -
that's why i post.

Below are two simple models Vocabulary and Term. A vocabulary contains
terms. When a new vocabulary is created (saved the first time), it
automatically creates a root term for the vocabulary.
Both models overload the save() method.

Running the unittest given below with django 0.97-newforms-admin-
SVN-7233 all tests pass fine.

When running the unittest given below with django 0.97-newforms-admin-
SVN-7599 the tests give the following error:

{{{
======================================================================
FAIL: test_qsrf (nmy.qsrftest.tests.QsrfTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/home/peter/src/nmy/site-packages/nmy/qsrftest/tests.py"", line
27, in test_qsrf
    self.failUnlessEqual(v.root, v.root.vocabulary.root)
AssertionError: <Term: Term object> != None

----------------------------------------------------------------------
}}}

I also tested this with  0.97-newforms-admin-SVN-7609 (which has some
bugfixes regarding queries) but the issue remains.

I tried to track down the problem, checked my unittest, checked my
models - but the only thing I could find is weird: As soon as I
reference the ``vocabulary`` field in a term's save() method the test
fails. If I remove all references to the ``vocabulary`` field from the
save() method the tests pass fine.
I found that a simple read-only operation like print or even a simple
no-op reference of the ``vocabulary`` field changes the behaviour of
the unittest.
The problem is arises when I use a relation from a Vocabulary to a
Term instance. The term instance has a field which relates back to
the Vocabulary - when using the relation to the vocabulary and
then again want to reference back to the term, the reference is empty.

In other words:
{{{
v.root != v.root.vocabulary.root (where v==vocabulary)
}}}
This is wrong, because it should be 
{{{
v.root == v.root.vocabulary.root
}}}

I apologize when this description is somehow confusing, but the
easiest way is to use the models and unittest below to demonstrate
the issue. The unitttest should fail (which is incorrect behaviour).
After commenting out the line in Term.save() the test runs fine 
(the out-commented line does nothing/is a read-only operation).
"		closed	Database layer (models, ORM)	dev		worksforme	qsrf unittest testclient		Accepted	0	0	0	0	0	0
