File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ def test_upsert_with_update_condition():
9090
9191 obj1 = model .objects .create (name = "joe" , priority = 1 , active = False )
9292
93- model .objects .upsert (
93+ # should not return anything because no rows were affected
94+ assert not model .objects .upsert (
9495 conflict_target = ["name" ],
9596 update_condition = CombinedExpression (
9697 model ._meta .get_field ("active" ).get_col (model ._meta .db_table ),
@@ -101,10 +102,25 @@ def test_upsert_with_update_condition():
101102 )
102103
103104 obj1 .refresh_from_db ()
104-
105105 assert obj1 .priority == 1
106106 assert not obj1 .active
107107
108+ # should return something because one row was affected
109+ obj1_pk = model .objects .upsert (
110+ conflict_target = ["name" ],
111+ update_condition = CombinedExpression (
112+ model ._meta .get_field ("active" ).get_col (model ._meta .db_table ),
113+ "=" ,
114+ Value (False ),
115+ ),
116+ fields = dict (name = "joe" , priority = 2 , active = True ),
117+ )
118+
119+ obj1 .refresh_from_db ()
120+ assert obj1 .pk == obj1_pk
121+ assert obj1 .priority == 2
122+ assert obj1 .active
123+
108124
109125def test_upsert_and_get_applies_converters ():
110126 """Tests that converters are properly applied when using upsert_and_get."""
You can’t perform that action at this time.
0 commit comments