File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -324,8 +324,14 @@ def check_query(self):
324324 )
325325
326326
327- class SQLUpdateCompiler (SQLCompiler ):
327+ class SQLUpdateCompiler (compiler . SQLUpdateCompiler , SQLCompiler ):
328328 def execute_sql (self , result_type ):
329+ """
330+ Execute the specified update. Return the number of rows affected by
331+ the primary update query. The "primary update query" is the first
332+ non-empty query that is executed. Row counts for any subsequent,
333+ related queries are not available.
334+ """
329335 self .pre_sql_setup ()
330336 values = []
331337 for field , _ , value in self .query .values :
@@ -340,7 +346,14 @@ def execute_sql(self, result_type):
340346 )
341347 prepared = field .get_db_prep_save (value , connection = self .connection )
342348 values .append ((field , prepared ))
343- return self .update (values )
349+ is_empty = not bool (values )
350+ rows = 0 if is_empty else self .update (values )
351+ for query in self .query .get_related_updates ():
352+ aux_rows = query .get_compiler (self .using ).execute_sql (result_type )
353+ if is_empty and aux_rows :
354+ rows = aux_rows
355+ is_empty = False
356+ return rows
344357
345358 def update (self , values ):
346359 spec = {}
Original file line number Diff line number Diff line change @@ -51,9 +51,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
5151 "update.tests.AdvancedTests.test_update_ordered_by_inline_m2m_annotation" ,
5252 "update.tests.AdvancedTests.test_update_ordered_by_m2m_annotation" ,
5353 "update.tests.AdvancedTests.test_update_ordered_by_m2m_annotation_desc" ,
54- # pymongo: ValueError: update cannot be empty
55- "update.tests.SimpleTest.test_empty_update_with_inheritance" ,
56- "update.tests.SimpleTest.test_nonempty_update_with_inheritance" ,
5754 # Pattern lookups that use regexMatch don't work on JSONField:
5855 # Unsupported conversion from array to string in $convert
5956 "model_fields.test_jsonfield.TestQuerying.test_icontains" ,
You can’t perform that action at this time.
0 commit comments