MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_update_no_params

Method test_update_no_params

test/sql/test_update.py:129–178  ·  test/sql/test_update.py::UpdateTest.test_update_no_params

test issue identified while doing #9721 UPDATE with empty VALUES but multiple tables would raise a NoneType error; fixed this to emit an empty "SET" the way a single table UPDATE currently does. both cases should probably raise CompileError, however this could

(self, values, twotable)

Source from the content-addressed store, hash-verified

127 @testing.variation(class="st">"twotable", [True, False])
128 @testing.variation(class="st">"values", [class="st">"none", class="st">"blank"])
129 def test_update_no_params(self, values, twotable):
130 class="st">"""test issue identified while doing class="cm">#9721
131
132 UPDATE with empty VALUES but multiple tables would raise a
133 NoneType error; fixed this to emit an empty class="st">"SET" the way a single
134 table UPDATE currently does.
135
136 both cases should probably raise CompileError, however this could
137 be backwards incompatible with current use cases (such as other test
138 suites)
139
140 class="st">"""
141
142 table1 = self.tables.mytable
143 table2 = self.tables.myothertable
144
145 stmt = table1.update().where(table1.c.name == class="st">"jill")
146 if twotable:
147 stmt = stmt.where(table2.c.otherid == table1.c.myid)
148
149 if values.blank:
150 stmt = stmt.values()
151
152 if twotable:
153 if values.blank:
154 self.assert_compile(
155 stmt,
156 class="st">"UPDATE mytable SET FROM myothertable "
157 class="st">"WHERE mytable.name = :name_1 "
158 class="st">"AND myothertable.otherid = mytable.myid",
159 )
160 elif values.none:
161 self.assert_compile(
162 stmt,
163 class="st">"UPDATE mytable SET myid=:myid, name=:name, "
164 class="st">"description=:description FROM myothertable "
165 class="st">"WHERE mytable.name = :name_1 "
166 class="st">"AND myothertable.otherid = mytable.myid",
167 )
168 elif values.blank:
169 self.assert_compile(
170 stmt,
171 class="st">"UPDATE mytable SET WHERE mytable.name = :name_1",
172 )
173 elif values.none:
174 self.assert_compile(
175 stmt,
176 class="st">"UPDATE mytable SET myid=:myid, name=:name, "
177 class="st">"description=:description WHERE mytable.name = :name_1",
178 )
179
180 def test_update_literal_binds(self):
181 table1 = self.tables.mytable

Callers

nothing calls this directly

Calls 4

assert_compileMethod · 0.80
whereMethod · 0.45
updateMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected