chore: add drf-lint pre-commit hook with baseline#3861
Open
blarghmatey wants to merge 1 commit intomasterfrom
Open
chore: add drf-lint pre-commit hook with baseline#3861blarghmatey wants to merge 1 commit intomasterfrom
blarghmatey wants to merge 1 commit intomasterfrom
Conversation
0db4e0c to
90a749b
Compare
90a749b to
45fabe2
Compare
Adds the drf-serializer-orm-check hook (mirroring the definition from mitodl/ol-django) to detect Django ORM queries inside DRF serializer methods (N+1 risk). Uses repo: local so pre-commit only installs mitol-drf-lint without attempting to pip-install the ol-django workspace root (which has internal workspace dependencies unavailable on PyPI). Generates an initial baseline file (drf_lint_baseline.json) recording existing violations so the hook only flags new issues going forward. Co-authored-by: Copilot <[email protected]>
45fabe2 to
f72c2e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are the relevant tickets?
N/A
Description (What does it do?)
Adds the
drf-serializer-orm-checkpre-commit hook from mitodl/ol-django which usesmitol-drf-lintto detect Django ORM queries inside DRF serializer methods — a common source of N+1 query bugs.Also generates an initial
drf_lint_baseline.jsonrecording all pre-existing violations so the hook only flags new issues going forward. Existing violations can be addressed incrementally.mitol-drf-lintis added as a dev dependency to support running the tool locally outside of pre-commit.How can this be tested?
pre-commit installserializers.pyfile that calls ORM methods (e.g..filter(),.get()) inside a serializer method bodyuv run drf-lint <path/to/serializers.py>Additional Context
The baseline was generated with:
To regenerate after fixing existing violations, rerun the above command.