#19095: Dubious code in multiple_database tests
-------------------------------------+-------------------------------------
               Reporter:  aaugustin  |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  master
  layer (models, ORM)                |       Keywords:
               Severity:  Normal     |      Has patch:  0
           Triage Stage:             |    Needs tests:  0
  Unreviewed                         |  Easy pickings:  0
    Needs documentation:  0          |
Patch needs improvement:  0          |
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 `QueryTestCase.test_o2o_cross_database_protection` contains code that
 seems invalid to me.

 In that test, `UserProfile` has a nullable one-to-one relation to `User`.

 An unsaved instance of `User` called `charlie` is created at line 655, and
 a profile is attached to this instance at line 664: `charlie.userprofile =
 bob_profile`.

 But after saving everything, that doesn't work as expected: the profile
 isn't linked to the user!

 This is easy to understand: this line basically performs
 `bob_profile.user_id = charlie.id` (and populates relation caches); but
 since `charlie` is unsaved, `charlie.id` is `None`, hence
 `bob_profile.used_id` remains `None`.

 I'm attaching a patch for this test case that reloads the objects and
 tests that `charlie.userprofile == bob_profile` ; with this patch, the
 test fails, proving my point.

 ----

 In #18153, I tried to catch such programming errors by raising an
 exception. And that breaks that test.

 I think this code needs to fixed, while preserving as much of the testing
 behavior as possible.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19095>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to