cosmicpython / code

Example application code for the python architecture book
Other
2.14k stars 943 forks source link

Chapter 4: we do `session.commit()` but do we have any changes to commit? #65

Closed konstunn closed 1 year ago

konstunn commented 1 year ago

https://github.com/cosmicpython/code/blob/952a3d2f53ec56ca320b8415097350799f38de10/services.py#L21

If I get it right, after the allocation take place in the service and domain layers, the changes are not saved to the database, because there isn't any call to the repository before we do session.commit().

So our allocation seems to not have been saved and thus is not persistent. We can make the same allocation many times again and again and never run out of stock.

konstunn commented 1 year ago

Sorry. I have missed that the domain models are mapped to the database tables via ORM mappers. So there is no need to call repository to save the changes. This work will be done by the sql alchemy orm mappers and session "automatically". Did I get it right now?

uguryilmazunified commented 1 year ago

yes that's my understanding too