Closed daredevil82 closed 9 months ago
it's definitely a bit of a head-scratcher. session.execute
returns the results of your SELECT
query, which the set of rows that match the query. each row is made up of columns. so the return type is a list of tuples. in this case i know it's exactly one row containing a tuple with exactly one item (the id
of the row in the order_lines
table), which is why the tuple unpacking works.
i could add a footnote maybe? i didn't want the focus of the book to be teaching people how to use sqlalchemy, but i don't want code listings to be so weird as to be obscure and cause people to wonder how on earth they work!
I had to read it twice and give it a few seconds of thoughts. A footnote should help !
Also for me, it would be a bit less confusing with
[(orderlineid, )] = ...
fixed here, thanks for the feedback everyone. https://github.com/cosmicpython/book/commit/609d5a2303c632012bee7105a6d83eb03f4b708a
In Chapter 5, a test for uow is displayed. However, it is using list unpacking, and its not obvious whether the difference between
orderlineid
andid
inis deliberate or a typo. If it is deliberate, it would be helpful to have an explanation of what SQLAlchemy's
orm.session
package is doing to return the thing referred to with the nameorderlineid