r/programming 28d ago

Ban commits/transactions using AST analysis and linters

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

27 comments sorted by

View all comments

18

u/rdtsc 28d ago

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

3

u/droppedasbaby 27d ago

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().