Working on a project that stores and fetches data in sqlalchemy, I encounter a confusing error in testing a custom filter function. The filter function returns a list of "Move Orders" from the database, and in testing I assert that this list is a subset of the list of all orders:
assert filtered_orders <= all_orders
I have three "Stockpoints" (other sqlalchemy table class) that may have MoveOrders associated with them, and running this test in a loop over each, it passes for all except the last "Stockpoint":
assert filtered_orders <= all_orders
TypeError: '<=' not supported between instances of 'MoveOrder' and 'MoveOrder'
As seen in the error message, on the last pass (last stockpoint), it evaluates the lists to be of type MoveOrder; the type of the lists' elements. Some further inspection:
print(f"types: {type(filtered_orders)} and {type(all_orders)}")
>types: <class 'list'> and <class 'list'>
assert isinstance(filtered_orders, list)
assert isinstance(all_orders, list)
assert filtered_orders <= all_orders
TypeError: '<=' not supported between instances of 'MoveOrder' and 'MoveOrder'
As you can see in the last code block, inspecting the variables filtered_orders and all_orders individually shows that they are of type list and pass individual isinstance() asserts... until the line where they are evaluated with the <= operator!
Any idea how this sudden "change of mind" could be occurring?