superset icon indicating copy to clipboard operation
superset copied to clipboard

chore: add pylint rule for SQL importing (SIP-117)

Open betodealmeida opened this issue 1 year ago • 7 comments

SUMMARY

Pylint rule to prevent Superset from importing SQL parsing libraries outside of superset/sql/. Should be merged once https://github.com/apache/superset/issues/26786 has been completed.

Note that https://github.com/apache/superset/pull/31262 removed pylint, preventing the custom plugins we have from running. I added pylint back, but with some performance optimizations:

  1. It runs only the custom rules (no json import, no commit, no SQL imports).
  2. It runs only for modified Python files.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

$ pylint --reports=no --score=no --disable=all --enable=C9999 superset/db_engine_specs/base.py
************* Module superset.db_engine_specs.base
superset/db_engine_specs/base.py:38:0: C9999: Disallowed SQL parsing import used (disallowed-import)
$ pylint --reports=no --score=no --disable=all --enable=C9999 superset/sql_parse.py
$

ADDITIONAL INFORMATION

  • [ ] Has associated issue:
  • [ ] Required feature flags:
  • [ ] Changes UI
  • [ ] Includes DB Migration (follow approval process in SIP-59)
    • [ ] Migration is atomic, supports rollback & is backwards-compatible
    • [ ] Confirm DB migration upgrade and downgrade tested
    • [ ] Runtime estimates and downtime expectations provided
  • [ ] Introduces new feature or API
  • [ ] Removes existing feature or API

betodealmeida avatar Jan 25 '24 18:01 betodealmeida

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Project coverage is 69.47%. Comparing base (424b4c2) to head (a3a2dbc). Report is 2425 commits behind head on master.

Files with missing lines Patch % Lines
superset/extensions/pylint.py 0.00% 20 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #26803      +/-   ##
==========================================
+ Coverage   67.16%   69.47%   +2.30%     
==========================================
  Files        1894     1895       +1     
  Lines       74176    74196      +20     
  Branches     8243     8243              
==========================================
+ Hits        49820    51546    +1726     
+ Misses      22287    20581    -1706     
  Partials     2069     2069              
Flag Coverage Δ
hive 100.00% <0.00%> (?)
mysql 100.00% <0.00%> (+22.03%) :arrow_up:
postgres 100.00% <0.00%> (+21.93%) :arrow_up:
presto 100.00% <0.00%> (?)
python 100.00% <0.00%> (+21.80%) :arrow_up:
sqlite 100.00% <0.00%> (+22.35%) :arrow_up:
unit 100.00% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jan 25 '24 18:01 codecov[bot]

Thanks for adding this @betodealmeida. As part of SIP-99 I was hoping to do something similar to prevent the use of db.session.commit() or db.session.rollback() commands given these will be handled via SQLAlchemy's context manager.

john-bodley avatar Jan 26 '24 00:01 john-bodley

I love that I can't merge this PR because of the rule it adds. 😆

I hope to be able to merge this soon...

betodealmeida avatar Feb 01 '24 21:02 betodealmeida

Is this mergeable now? Closing/reopening to kick-start CI, though it probably needs a rebase.

rusackas avatar Sep 04 '24 21:09 rusackas

Converting this to draft mode whilst it awaits a rebase/revisit.

rusackas avatar Apr 22 '25 21:04 rusackas

I hope to be able to merge this soon...

5 months later...

betodealmeida avatar Jun 05 '25 14:06 betodealmeida

@betodealmeida looks like pre-commit is failing in this pr

sadpandajoe avatar Jun 12 '25 17:06 sadpandajoe