File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -106,12 +106,24 @@ def insert_and_get(self, **fields):
106106 """
107107
108108 if not self .conflict_target and not self .conflict_action :
109+ print ('oh fuck' );
109110 # no special action required, use the standard Django create(..)
110111 return super ().create (** fields )
111112
112113 compiler = self ._build_insert_compiler (** fields )
113114 rows = compiler .execute_sql (return_id = False )
114- column_data = rows [0 ]
115+
116+ columns = rows [0 ]
117+
118+ # it could happen that in the case of ConflictAction.NOTHING, the
119+ # row already existed, and in that case, we have to do an extra SELECT
120+ if not columns :
121+ select_fields = {
122+ field : fields [field ]
123+ for field in self .conflict_target
124+ }
125+
126+ return self .get (** select_fields )
115127
116128 # get a list of columns that are officially part of the model
117129 model_columns = [
@@ -122,7 +134,7 @@ def insert_and_get(self, **fields):
122134 # strip out any columns/fields returned by the db that
123135 # are not present in the model
124136 model_init_fields = {}
125- for column_name , column_value in column_data .items ():
137+ for column_name , column_value in columns .items ():
126138 if column_name not in model_columns :
127139 continue
128140
You can’t perform that action at this time.
0 commit comments