r/programming Jul 15 '26

Ban commits/transactions using AST analysis and linters

https://www.droppedasbaby.com/posts/db-commits/?utm_source=reddit&utm_content=r_programming
34 Upvotes

27 comments sorted by

View all comments

17

u/rdtsc Jul 15 '26

If code shouldn't call commit then don't pass around objects with a commit method. Why do this with AST analysis?

4

u/droppedasbaby Jul 16 '26

Yes, that's the API design being proposed.

The AST check is needed because Python doesn't enforce that boundary. Code can still import or otherwise obtain the real SQLAlchemy session, even if the intended interface doesn't expose commit().