Code

#19095 closed Bug (fixed)

Dubious code in multiple_database tests

Reported by: aaugustin Owned by: nobody
Component: Database layer (models, ORM) Version: master
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)

19095-show-invalid-result.diff (880 bytes) - added by aaugustin 21 months ago.

Download all attachments as: .zip

Change History (2)

Changed 21 months ago by aaugustin

comment:1 Changed 21 months ago by Aymeric Augustin <aymeric.augustin@…>

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

In c9b4e9ac3a6c56f2b006b723972e77722d3ac937:

Fixed #19095 -- invalid code in multidb tests.

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.