Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#8542 closed (fixed)

model_formsets tests added in r8528 fail on MySQL

Reported by: Karen Tracey <kmtracey@…> Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The model_formsets tests added in [8528] are failing on MySQL:

======================================================================
FAIL: Doctest: modeltests.model_formsets.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kmt/tmp/django/trunk/django/test/_doctest.py", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for modeltests.model_formsets.models.__test__.API_TESTS
  File "/home/kmt/tmp/django/trunk/tests/modeltests/model_formsets/models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "/home/kmt/tmp/django/trunk/tests/modeltests/model_formsets/models.py", line ?, in modeltests.model_formsets.models.__test__.API_TESTS
Failed example:
    for form in formset.forms:
        print form.as_p()
Expected:
    <p><label for="id_form-0-name">Name:</label> <input id="id_form-0-name" type="text" name="form-0-name" value="Ernest Hemingway" maxlength="100" /></p>
    <p><label for="id_form-0-write_speed">Write speed:</label> <input type="text" name="form-0-write_speed" value="10" id="id_form-0-write_speed" /><input type="hidden" name="form-0-author_ptr_id" value="4" id="id_form-0-author_ptr_id" /></p>
    <p><label for="id_form-1-name">Name:</label> <input id="id_form-1-name" type="text" name="form-1-name" maxlength="100" /></p>
    <p><label for="id_form-1-write_speed">Write speed:</label> <input type="text" name="form-1-write_speed" id="id_form-1-write_speed" /><input type="hidden" name="form-1-author_ptr_id" id="id_form-1-author_ptr_id" /></p>
Got:
    <p><label for="id_form-0-name">Name:</label> <input id="id_form-0-name" type="text" name="form-0-name" value="Ernest Hemingway" maxlength="100" /></p>
    <p><label for="id_form-0-write_speed">Write speed:</label> <input type="text" name="form-0-write_speed" value="10" id="id_form-0-write_speed" /><input type="hidden" name="form-0-author_ptr_id" value="5" id="id_form-0-author_ptr_id" /></p>
    <p><label for="id_form-1-name">Name:</label> <input id="id_form-1-name" type="text" name="form-1-name" maxlength="100" /></p>
    <p><label for="id_form-1-write_speed">Write speed:</label> <input type="text" name="form-1-write_speed" id="id_form-1-write_speed" /><input type="hidden" name="form-1-author_ptr_id" id="id_form-1-author_ptr_id" /></p>
----------------------------------------------------------------------
File "/home/kmt/tmp/django/trunk/tests/modeltests/model_formsets/models.py", line ?, in modeltests.model_formsets.models.__test__.API_TESTS
Failed example:
    formset.save()
Exception raised:
    Traceback (most recent call last):
      File "/home/kmt/tmp/django/trunk/django/test/_doctest.py", line 1267, in __run
        compileflags, 1) in test.globs
      File "<doctest modeltests.model_formsets.models.__test__.API_TESTS[64]>", line 1, in <module>
        formset.save()
      File "/home/kmt/tmp/django/trunk/django/forms/models.py", line 280, in save
        return self.save_existing_objects(commit) + self.save_new_objects(commit)
      File "/home/kmt/tmp/django/trunk/django/forms/models.py", line 294, in save_existing_objects
        obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]]
    KeyError: 4


----------------------------------------------------------------------
Ran 1 test in 0.253s

FAILED (failures=1)

For the first one the difference I notice is "value=4" (expected) vs. "value=5" (got) on the 2nd line. Probably the same problem causing the KeyError: 4 in the 2nd case -- some PK ID is turning out to be 5 on MySQL whereas it comes up 4 on the other backends? So the tests that look for value 4 and/or try to use that value are failing on MySQL?

Change History (6)

comment:1 by Malcolm Tredinnick, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

Tracked this down to [8528] being the commit that started the failure (and the test in question wasn't added in that commit).

in reply to:  1 comment:2 by Karen Tracey <kmtracey@…>, 16 years ago

Replying to mtredinnick:

Tracked this down to [8528] being the commit that started the failure (and the test in question wasn't added in that commit).

model_formsets overall wasn't added in that commit, but it is the stuff under

# Model inheritance in model formsets ######################################## 

added in that commit that is failing, right?

comment:3 by Malcolm Tredinnick, 16 years ago

Yes, Karen's right. I looked at the first for-loop in that new section and saw it didn't match. But it's the second for-loop (searching for "Hemingway" was a better guess) over the formset that is breaking.

En passant, this isn't MySQL-specific. When running the full test suite for something else, I saw it fail identically with both PostgreSQL backends.

comment:4 by Malcolm Tredinnick, 16 years ago

The problem here really is just with the test, not the code it's testing. The commit I'm about to make weakens the test for the precise characters in the form.as_p() output by avoiding the key value and then checks it's correct later on. We can't do a lot better than that with a doctest without writing something really messy, but all it hides is potential extra attributes being introduced, which isn't the sort of regression we've tended to make in that area.

comment:5 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [8563]) Fixed #8542 -- Made the model_formstests tests from [8528] a little less
dependent upon the precise values of auto-created primary key integers.

comment:6 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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