Opened 12 years ago
Closed 12 years ago
#19095 closed Bug (fixed)
Dubious code in multiple_database tests
Reported by: | Aymeric Augustin | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (1)
Change History (2)
by , 12 years ago
Attachment: | 19095-show-invalid-result.diff added |
---|
comment:1 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In c9b4e9ac3a6c56f2b006b723972e77722d3ac937: