deallocate and fix issues by uguryiilmz · Pull Request #114 · cosmicpython/code
I couldn't find the solution to the exercise for deallocation, so I wanted to share my own. Couple realization I had:
- there are typos in certain places, instead of returning batchref, it returns batch id. They're fixed in the code.
- sqlalchemy version is not pinned, so it'll try to install the latest one which is not compatible with the source code.(updated the requirements.txt)
- sku number is really not used anywhere logically for the deallocation method, as we cannot allocate anything to a batch if orderline and batch id doesn't match. we also know that orderline needs to unique, so data modeling doesn't really give any room to use sku for deallocation, I was not sure why it was included in the exercises to be used, maybe an oversight? I still used it as a placeholder but has no functional importance
Comment on lines +23 to +26
| for batch in self._batches: | ||
| for line in batch._allocations: | ||
| if line.orderid == order_id and line.sku == sku: | ||
| return line |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't resist suggesting this formulation with next() and a nested list comp. lol
return next( (l for b in self._batches for l in b._allocations if l.orderid == order_id and l.sku == sku), None, )
Hey, looks good! great job. hope you found the exercise interesting? i think you may be right about the sku...
@hjwp Thanks, Harry. I found the book extremely helpful. This is my second time reading it, and I decided to buy a copy because I'll always carry this around. Especially in the age of AI, architecture and maintenance will be more crucial than ever. Grateful for all the hard-earned experience and wisdom that you shared in the book.