Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#7419 closed (worksforme)

Testing framework or model save behaves differently after qsrf merge (r7233/r7599)

Reported by: peschler Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qsrf unittest testclient
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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).

Attachments (2)

models.py (956 bytes ) - added by peschler 16 years ago.
Models for the unittest demonstrating the issue.
tests.py (921 bytes ) - added by peschler 16 years ago.
Unittest to demonstrate the issue.

Download all attachments as: .zip

Change History (5)

by peschler, 16 years ago

Attachment: models.py added

Models for the unittest demonstrating the issue.

by peschler, 16 years ago

Attachment: tests.py added

Unittest to demonstrate the issue.

comment:1 by Jacob, 16 years ago

Component: Unit test systemDatabase wrapper
milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: worksforme
Status: newclosed

As at [8400], the provided test case is passing for me. I don't know what was causing the problem, but it appears to have been fixed.

comment:3 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top