Adding altered objects to sessions without committing #210
Replies: 1 comment
-
|
Fragment from a conversation that lead to this decision:
this is an interesting idea, but i wonder if it won't make our method names too long? the more we discuss the more I think that somebody who gets a session should not commit it. alternative would be to not pass the session at all anymore, but instead such methods that aim to modify the DB model always return the objects that have to be added to the session and committed? e.g. then the caller, probably the api endpoint who already has a session handy does do you see what I mean? surely, this might become complicated, because when you want to add multiple objects then you have to have to create a temporary array to which you add all these objects, and then you return it. So probably the solution above with passing the session and adding directly to it is still the most concise. And functionally it's exactly the same as the one with returning the objects to be added. However, in a sense it's more clear that things have to be added to the session. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A method that alters objects that are mapped via SQLAlchemy to the DB should append the objects to the session, but not commit the session. Instead the commit should be done by the method that has obtained independently the session and has passed it down to to the other methods.
Correct:
Incorrect:
Beta Was this translation helpful? Give feedback.
All reactions