@@ -169,11 +169,11 @@ def insert_batch(session, ref, sku, qty, eta):
169
169
170
170
171
171
def get_allocated_batch_ref(session, orderid, sku):
172
- [[orderlineid]] = session.execute(
172
+ [[orderlineid]] = session.execute( #<1>
173
173
"SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku",
174
174
dict(orderid=orderid, sku=sku),
175
175
)
176
- [[batchref]] = session.execute(
176
+ [[batchref]] = session.execute( #<1>
177
177
"SELECT b.reference FROM allocations JOIN batches AS b ON batch_id = b.id"
178
178
" WHERE orderline_id=:orderlineid",
179
179
dict(orderlineid=orderlineid),
@@ -182,7 +182,15 @@ def get_allocated_batch_ref(session, orderid, sku):
182
182
----
183
183
====
184
184
185
- // TODO: that double-unpacking is freaking ppl out. maybe [(orderlineid, )] ?
185
+ <1> The `[[orderlineid]] =` syntax is a little too-clever-by-half, apologies.
186
+ What's happening is that `session.execute` returns a list of rows,
187
+ where each row is a tuple of column values;
188
+ in our specific case, it's a list of one row,
189
+ which is a tuple with one column value in.
190
+ The double-square-bracket on the left hand side
191
+ is doing (double) assignment-unpacking to get the single value
192
+ back out of these two nested sequences.
193
+ It becomes readable once you've used it a few times!
186
194
187
195
188
196
=== Unit of Work and Its Context Manager
0 commit comments