1

I had an experience with slow sqlalchemy subquery using syntax Query.select_from(). Based on this experience, I want to get warning everytime certain syntax is used in our codebase. For example, when programmers add this code bellow, I want to get warnings.

q = session.query(Address).select_from(User).\
    join(User.addresses).\
    filter(User.name == 'ed')

Is there any linter or tools that can do this?

pupil
  • 318
  • 2
  • 16

1 Answers1

0

Ideally, you would set a pre-receive hook on the remote Git repo hosting server, like this one, in order to read the pushed files and grep for "query.*\.select_from": if detected, that hook would reject the push.

If you don't have access to the remote server (for instance GitHub), you would need to set a webhook instead.

The alternative is to deploy a pre-push hook to all clients, and do the check there, but that could be bypassed, or could be not deployed to everybody.
A server side hook / webhook is safer.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the suggestion. I think i will try pre-push hook first, then maybe set up webhook. – pupil Aug 30 '18 at 11:22