From 4183031560423a3d2a96b5ecdc57bcf551d0d8a9 Mon Sep 17 00:00:00 2001 From: Arbab Khalil Date: Mon, 24 Jan 2022 18:36:10 +0500 Subject: [PATCH 1/2] chore: add reserved keywords linter --- .github/workflows/ci.yml | 2 +- Makefile | 6 +++++- db_keyword_overrides.yml | 10 ++++++++++ tox.ini | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 db_keyword_overrides.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 442226f..2c29644 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: matrix: os: [ubuntu-20.04] python-version: ['3.8'] - toxenv: [django22-drf312, django30-drf312, django31-drf312, django32-drf312, django32-drflatest, quality, docs] + toxenv: [django22-drf312, django30-drf312, django31-drf312, django32-drf312, django32-drflatest, quality, docs, check_keywords] steps: - uses: actions/checkout@v2 diff --git a/Makefile b/Makefile index e97ec1f..f5e3352 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ endef export BROWSER_PYSCRIPT BROWSER := python -c "$$BROWSER_PYSCRIPT" -.PHONY: clean, coverage, diff_cover, docs, help, dev_requirements, test, test_quality, test_requirements, upgrade +.PHONY: clean, coverage, diff_cover, docs, help, dev_requirements, test, test_quality, test_requirements, upgrade,\ + check_keywords help: ## Display this help message @echo "Please use \`make ' where is one of" @@ -69,6 +70,9 @@ test_quality: ## Run Quality checks isort --check-only submissions manage.py setup.py settings.py pycodestyle . --config=pycodestyle +check_keywords: ## Scan the Django models in all installed apps in this project for restricted field names + python manage.py check_reserved_keywords --override_file db_keyword_overrides.yml + ################## #Devstack commands ################## diff --git a/db_keyword_overrides.yml b/db_keyword_overrides.yml new file mode 100644 index 0000000..dcc39cd --- /dev/null +++ b/db_keyword_overrides.yml @@ -0,0 +1,10 @@ +# This file is used by the 'check_reserved_keywords' management command to allow specific field names to be overridden +# when checking for conflicts with lists of restricted keywords used in various database/data warehouse tools. +# For more information, see: https://github.com/edx/edx-django-release-util/release_util/management/commands/check_reserved_keywords.py +# +# overrides should be added in the following format: +# - ModelName.field_name +--- +MYSQL: +SNOWFLAKE: +STITCH: diff --git a/tox.ini b/tox.ini index 54d07cf..d7f2f0c 100644 --- a/tox.ini +++ b/tox.ini @@ -32,3 +32,10 @@ deps = commands = python setup.py build_sphinx +[testenv:check_keywords] +whitelist_externals = + make +deps = + -r{toxinidir}/requirements/dev.txt +commands = + make check_keywords From 8a0a62e12163a43202be4d9e13a8a435bb25aeac Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Thu, 30 May 2024 10:58:59 +0930 Subject: [PATCH 2/2] chore: adds edx-django-release-util to the requirements and INSTALLED_APPS to support the check_reserved_keywords management command. --- requirements/base.in | 1 + requirements/base.txt | 7 +++++++ requirements/dev.txt | 11 +++++++++++ requirements/docs.txt | 9 +++++++++ requirements/test.txt | 13 ++++++++++++- settings.py | 4 ++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/requirements/base.in b/requirements/base.in index 18a523f..9d938c3 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -7,3 +7,4 @@ django-model-utils jsonfield pytz djangorestframework +edx-django-release-util diff --git a/requirements/base.txt b/requirements/base.txt index d05b414..dfa7040 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -17,15 +17,22 @@ django==4.2.13 # -r requirements/base.in # django-model-utils # djangorestframework + # edx-django-release-util # jsonfield django-model-utils==4.5.1 # via -r requirements/base.in djangorestframework==3.15.1 # via -r requirements/base.in +edx-django-release-util==1.4.0 + # via -r requirements/base.in jsonfield==3.1.0 # via -r requirements/base.in pytz==2024.1 # via -r requirements/base.in +pyyaml==6.0.1 + # via edx-django-release-util +six==1.16.0 + # via edx-django-release-util sqlparse==0.5.0 # via django typing-extensions==4.11.0 diff --git a/requirements/dev.txt b/requirements/dev.txt index 53df241..af64bbe 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -86,6 +86,7 @@ django==4.2.13 # -r requirements/test.txt # django-model-utils # djangorestframework + # edx-django-release-util # jsonfield django-model-utils==4.5.1 # via @@ -103,6 +104,11 @@ docutils==0.19 # -r requirements/test.txt # pydata-sphinx-theme # sphinx +edx-django-release-util==1.4.0 + # via + # -r requirements/base.txt + # -r requirements/docs.txt + # -r requirements/test.txt edx-lint==5.3.6 # via -r requirements/test.txt exceptiongroup==1.2.1 @@ -247,8 +253,11 @@ pytz==2024.1 # babel pyyaml==6.0.1 # via + # -r requirements/base.txt + # -r requirements/docs.txt # -r requirements/test.txt # code-annotations + # edx-django-release-util requests==2.32.2 # via # -r requirements/docs.txt @@ -256,8 +265,10 @@ requests==2.32.2 # sphinx six==1.16.0 # via + # -r requirements/base.txt # -r requirements/docs.txt # -r requirements/test.txt + # edx-django-release-util # edx-lint # pockets # python-dateutil diff --git a/requirements/docs.txt b/requirements/docs.txt index d943bf8..2257704 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -34,6 +34,7 @@ django==4.2.13 # -r requirements/base.txt # django-model-utils # djangorestframework + # edx-django-release-util # jsonfield django-model-utils==4.5.1 # via -r requirements/base.txt @@ -43,6 +44,8 @@ docutils==0.19 # via # pydata-sphinx-theme # sphinx +edx-django-release-util==1.4.0 + # via -r requirements/base.txt idna==3.7 # via requests imagesize==1.4.1 @@ -74,10 +77,16 @@ pytz==2024.1 # via # -r requirements/base.txt # babel +pyyaml==6.0.1 + # via + # -r requirements/base.txt + # edx-django-release-util requests==2.32.2 # via sphinx six==1.16.0 # via + # -r requirements/base.txt + # edx-django-release-util # pockets # sphinxcontrib-napoleon snowballstemmer==2.2.0 diff --git a/requirements/test.txt b/requirements/test.txt index 2a69172..8ad0ce5 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -66,6 +66,7 @@ dill==0.3.8 # -r requirements/docs.txt # django-model-utils # djangorestframework + # edx-django-release-util # jsonfield django-model-utils==4.5.1 # via @@ -79,6 +80,10 @@ docutils==0.19 # -r requirements/docs.txt # pydata-sphinx-theme # sphinx +edx-django-release-util==1.4.0 + # via + # -r requirements/base.txt + # -r requirements/docs.txt edx-lint==5.3.6 # via -r requirements/test.in exceptiongroup==1.2.1 @@ -188,14 +193,20 @@ pytz==2024.1 # -r requirements/docs.txt # babel pyyaml==6.0.1 - # via code-annotations + # via + # -r requirements/base.txt + # -r requirements/docs.txt + # code-annotations + # edx-django-release-util requests==2.32.2 # via # -r requirements/docs.txt # sphinx six==1.16.0 # via + # -r requirements/base.txt # -r requirements/docs.txt + # edx-django-release-util # edx-lint # pockets # python-dateutil diff --git a/settings.py b/settings.py index 26c5344..d718f05 100644 --- a/settings.py +++ b/settings.py @@ -28,6 +28,9 @@ }, } +# New DB primary keys default to an IntegerField. +DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' + CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', @@ -54,6 +57,7 @@ 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', + 'release_util', # Submissions 'submissions'