Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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: master
Severity: Keywords: qsrf unittest testclient
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 6 years ago.
Models for the unittest demonstrating the issue.
tests.py (921 bytes) - added by peschler 6 years ago.
Unittest to demonstrate the issue.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by peschler

Models for the unittest demonstrating the issue.

Changed 6 years ago by peschler

Unittest to demonstrate the issue.

comment:1 Changed 6 years ago by jacob

  • Component changed from Unit test system to Database wrapper
  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by russellm

  • Resolution set to worksforme
  • Status changed from new to closed

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 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.