From 193b3ba68c05e7ddf83c67b669a4e7b8b3dd2618 Mon Sep 17 00:00:00 2001 From: Davide bert Date: Tue, 15 Mar 2022 09:01:40 +0100 Subject: [PATCH 01/15] update_job force_update on save Sometimes django makes INSERT instead of UPDATE in certain conditions https://stackoverflow.com/questions/55954010/django-tries-to-insert-instead-of-update-on-save --- django_apscheduler/jobstores.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_apscheduler/jobstores.py b/django_apscheduler/jobstores.py index 6c05434..867467f 100644 --- a/django_apscheduler/jobstores.py +++ b/django_apscheduler/jobstores.py @@ -255,7 +255,7 @@ def update_job(self, job: AppSchedulerJob): job.__getstate__(), self.pickle_protocol ) - db_job.save() + db_job.save(force_update=True) except DjangoJob.DoesNotExist: raise JobLookupError(job.id) From a706458e7218048c4a8834a819369bdf1e3c0bf6 Mon Sep 17 00:00:00 2001 From: Davide bert Date: Tue, 22 Mar 2022 09:27:08 +0100 Subject: [PATCH 02/15] select_for_update --- django_apscheduler/jobstores.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/django_apscheduler/jobstores.py b/django_apscheduler/jobstores.py index 867467f..cdca9f3 100644 --- a/django_apscheduler/jobstores.py +++ b/django_apscheduler/jobstores.py @@ -248,24 +248,25 @@ def update_job(self, job: AppSchedulerJob): # Acquire lock for update with transaction.atomic(): try: - db_job = DjangoJob.objects.get(id=job.id) + db_job = DjangoJob.objects.select_for_update().get(id=job.id) db_job.next_run_time = get_django_internal_datetime(job.next_run_time) db_job.job_state = pickle.dumps( job.__getstate__(), self.pickle_protocol ) - db_job.save(force_update=True) + db_job.save() except DjangoJob.DoesNotExist: raise JobLookupError(job.id) @util.retry_on_db_operational_error def remove_job(self, job_id: str): - try: - DjangoJob.objects.get(id=job_id).delete() - except DjangoJob.DoesNotExist: - raise JobLookupError(job_id) + with transaction.atomic(): + try: + DjangoJob.objects.select_for_update().get(id=job_id).delete() + except DjangoJob.DoesNotExist: + raise JobLookupError(job_id) @util.retry_on_db_operational_error def remove_all_jobs(self): From caa0006973413a6502b2447b25e3893f28004c77 Mon Sep 17 00:00:00 2001 From: johncass Date: Fri, 22 Jul 2022 15:21:33 +0200 Subject: [PATCH 03/15] test: Update test cases. --- tests/test_jobstores.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_jobstores.py b/tests/test_jobstores.py index b721e3a..c76a044 100644 --- a/tests/test_jobstores.py +++ b/tests/test_jobstores.py @@ -237,7 +237,7 @@ def test_update_job_does_retry_on_db_operational_error(self, jobstore, create_jo with mock.patch.object(db.connection, "close") as close_mock: with pytest.raises(db.OperationalError, match="Some DB-related error"): with mock.patch( - "django_apscheduler.jobstores.DjangoJob.objects.get", + "django_apscheduler.jobstores.DjangoJob.objects.select_for_update", side_effect=conftest.raise_db_operational_error, ): jobstore.update_job(job) @@ -249,7 +249,7 @@ def test_remove_job_does_retry_on_db_operational_error(self, jobstore): with mock.patch.object(db.connection, "close") as close_mock: with pytest.raises(db.OperationalError, match="Some DB-related error"): with mock.patch( - "django_apscheduler.jobstores.DjangoJob.objects.get", + "django_apscheduler.jobstores.DjangoJob.objects.select_for_update", side_effect=conftest.raise_db_operational_error, ): jobstore.remove_job("some job") From a792c1a78881cca8bb38d47767713a74436c3c4a Mon Sep 17 00:00:00 2001 From: johncass Date: Fri, 22 Jul 2022 15:21:42 +0200 Subject: [PATCH 04/15] docs: Update changelog. --- docs/changelog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 02eae40..c0870a9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,13 @@ This changelog is used to track all major changes to django-apscheduler. +## v0.6.3 (UNRELEASED) + +**Fixes** + +- Take a database lock before updating / deleting job store entries to prevent duplicate key violation errors (thanks + @calledbert). + ## v0.6.2 (2022-03-06) **Fixes** From d47457f12230ad9a5024a3eba07bba5a97318b1e Mon Sep 17 00:00:00 2001 From: johncass Date: Sun, 7 Jul 2024 17:37:32 +0200 Subject: [PATCH 05/15] docs: Looking for new maintainer. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 9cfa100..efc4a21 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +## WARNING: This project is no longer actively maintained. + +It has been a few years since I have worked on any Django applications in production, and I am not making use of this +codebase myself anymore. + +We have an [issue open](https://github.com/jcass77/django-apscheduler/issues/190) to look for a new maintainer. Please +comment there if you are interested in becoming involved. + Django APScheduler ================== From 71cd17fae6bdf4cef9b4e831e3057eb3da714e90 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Wed, 18 Sep 2024 19:12:06 +0900 Subject: [PATCH 06/15] ci: add tests for newer python and django versions --- .github/workflows/python-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index b7c00b4..3edbf2a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -34,8 +34,8 @@ jobs: needs: lint strategy: matrix: - python-version: [ 3.8, 3.9, "3.10" ] - django-version: [ "3.2", "4.0" ] + python-version: [ 3.8, 3.9, 3.10, 3.11, 3.12 ] + django-version: [ "3.2", "4.0", "5.0", "5.1" ] env: PYTHON: ${{ matrix.python-version }} DJANGO: ${{ matrix.django-version }} From 23b5cf9ca094bc912bb444cc0efb310a1ed95a9d Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Wed, 18 Sep 2024 19:49:00 +0900 Subject: [PATCH 07/15] test: bump pytest version, and remove unnecessary pytest-pythonpath from requirements/local.txt --- pytest.ini | 6 +----- requirements/local.txt | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pytest.ini b/pytest.ini index 1562108..fac9915 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,9 +1,5 @@ [pytest] +pythonpath = . python_files = tests.py test_*.py *_tests.py - -;https://github.com/bigsassy/pytest-pythonpath#usage -python_paths = tests/ - addopts = --ds=tests.settings - norecursedirs = django_apscheduler diff --git a/requirements/local.txt b/requirements/local.txt index fd1375c..4a3e08b 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -2,9 +2,9 @@ # Testing # ------------------------------------------------------------------------------ -pytest~=6.2 # https://github.com/pytest-dev/pytest +tox==4.19.0 # https://github.com/tox-dev/tox +pytest>7.0.0 # https://github.com/pytest-dev/pytest pytest-sugar~=0.9 # https://github.com/Frozenball/pytest-sugar -pytest-pythonpath~=0.7 # https://github.com/bigsassy/pytest-pythonpath # Django # ------------------------------------------------------------------------------ From ec5aaa9866380c323a85abb909fe2bd9fbb1b28e Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Wed, 18 Sep 2024 20:04:59 +0900 Subject: [PATCH 08/15] test: update ci to use tox --- .github/workflows/python-package.yml | 119 ++++++++++++++------------- tox.ini | 19 +++++ 2 files changed, 81 insertions(+), 57 deletions(-) create mode 100644 tox.ini diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3edbf2a..d615ed3 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -4,62 +4,67 @@ name: Python package on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] + push: + branches: [ develop ] + pull_request: + branches: [ develop ] jobs: - lint: - name: Check code style - runs-on: ubuntu-latest - container: python:3-slim - steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 black - - name: Blacken code - run: black . --safe --quiet - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - test: - name: Test (Python, Django) - runs-on: ubuntu-latest - needs: lint - strategy: - matrix: - python-version: [ 3.8, 3.9, 3.10, 3.11, 3.12 ] - django-version: [ "3.2", "4.0", "5.0", "5.1" ] - env: - PYTHON: ${{ matrix.python-version }} - DJANGO: ${{ matrix.django-version }} - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade django~=${{ matrix.django-version }} - if [ -f requirements/local.txt ]; then pip install -r requirements/local.txt; fi - - name: Test with pytest and update coverage - run: | - coverage run -m pytest - coverage xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: coverage.xml - flags: unittests - env_vars: PYTHON, DJANGO - fail_ci_if_error: true - verbose: true + lint: + name: Check code style + runs-on: ubuntu-latest + container: python:3-slim + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 black + - name: Blacken code + run: black . --safe --quiet + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + tests: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-20.04 + + strategy: + matrix: + python-version: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: 'requirements/*.txt' + + - name: Upgrade packaging tools + run: python -m pip install --upgrade pip setuptools virtualenv wheel + + - name: Install dependencies + run: python -m pip install --upgrade codecov tox + + - name: Run tox targets for ${{ matrix.python-version }} + run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d . | cut -f 1 -d '-') + + - name: Run extra tox targets + if: ${{ matrix.python-version == '3.9' }} + run: | + tox -e base,dist,docs + + - name: Upload coverage + run: | + codecov -e TOXENV,DJANGO \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..3cadaf9 --- /dev/null +++ b/tox.ini @@ -0,0 +1,19 @@ +[tox] +envlist = + {py38,py39}-{django42} + {py310}-{django42,django50,django51,djangomain} + {py311}-{django42,django50,django51,djangomain} + {py312}-{django42,django50,django51,djangomain} + +[testenv] +setenv = + PYTHONPATH = {toxinidir} +deps = + pytest + pytest-django + django42: django>=4.2,<5.0 + django50: django>=5.0,<5.1 + django51: django>=5.1,<5.2 + djangomain: https://github.com/django/django/archive/main.tar.gz +commands = + pytest \ No newline at end of file From a252c14b75b1a82fdb4f29fadde56cf3289477d3 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Wed, 18 Sep 2024 20:17:21 +0900 Subject: [PATCH 09/15] test: remove unnecessary step --- .github/workflows/python-package.yml | 52 +++++++++++----------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index d615ed3..ad83db9 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -32,39 +32,27 @@ jobs: tests: name: Python ${{ matrix.python-version }} runs-on: ubuntu-20.04 - strategy: matrix: python-version: - - '3.8' - - '3.9' - - '3.10' - - '3.11' - - '3.12' - + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: 'requirements/*.txt' - - - name: Upgrade packaging tools - run: python -m pip install --upgrade pip setuptools virtualenv wheel - - - name: Install dependencies - run: python -m pip install --upgrade codecov tox - - - name: Run tox targets for ${{ matrix.python-version }} - run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d . | cut -f 1 -d '-') - - - name: Run extra tox targets - if: ${{ matrix.python-version == '3.9' }} - run: | - tox -e base,dist,docs - - - name: Upload coverage - run: | - codecov -e TOXENV,DJANGO \ No newline at end of file + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: 'requirements/*.txt' + - name: Upgrade packaging tools + run: python -m pip install --upgrade pip setuptools virtualenv wheel + - name: Install dependencies + run: python -m pip install --upgrade codecov tox + - name: Run tox targets for ${{ matrix.python-version }} + run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d . | cut -f 1 -d '-') + - name: Upload coverage + run: | + codecov -e TOXENV,DJANGO \ No newline at end of file From d483d0e03dd1a490b0bebbb84e68a076f8ec3558 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Thu, 19 Sep 2024 15:07:01 +0900 Subject: [PATCH 10/15] chore: drop support for python 3.8 && django 3.2 --- .github/workflows/python-package.yml | 1 - setup.py | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ad83db9..c2f728e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -35,7 +35,6 @@ jobs: strategy: matrix: python-version: - - '3.8' - '3.9' - '3.10' - '3.11' diff --git a/setup.py b/setup.py index 511f0ab..80010a7 100644 --- a/setup.py +++ b/setup.py @@ -26,17 +26,19 @@ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Framework :: Django", - "Framework :: Django :: 3.2", - "Framework :: Django :: 4.0", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", + "Framework :: Django :: 5.1", ], keywords="django apscheduler django-apscheduler", packages=find_packages(exclude=("tests",)), install_requires=[ - "django>=3.2", + "django>=4.2", "apscheduler>=3.2,<4.0", ], zip_safe=False, From 1d38aecc54056841d669f31d5657405f039e7792 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Thu, 19 Sep 2024 15:07:11 +0900 Subject: [PATCH 11/15] docs: add authors --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 55f0887..edef57f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ - Jarek Glowacki - Stas Kaledin - John Cass +- JAEGYUN JUNG \ No newline at end of file From 5ef7aa1b60d5c1c8fb95647cfca55cf731cd801e Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Thu, 19 Sep 2024 18:02:26 +0900 Subject: [PATCH 12/15] test: drop testing python3.8 in tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 3cadaf9..6bc1385 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - {py38,py39}-{django42} + {py39}-{django42} {py310}-{django42,django50,django51,djangomain} {py311}-{django42,django50,django51,djangomain} {py312}-{django42,django50,django51,djangomain} From 49b227e30cc0c90b0ab8d3fa3bcca8b1e4372c83 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Thu, 19 Sep 2024 23:57:35 +0900 Subject: [PATCH 13/15] chore: prepare version 0.7.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 80010a7..ec9cf44 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name="django-apscheduler", - version="0.6.2", + version="0.7.0", description="APScheduler for Django", long_description=long_description, long_description_content_type="text/markdown", From 5541e5ead41c024f64b50fea60a175fdc0f81d42 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Tue, 24 Sep 2024 01:37:24 +0900 Subject: [PATCH 14/15] docs: update changelog.md --- docs/changelog.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index c0870a9..32ef57f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,8 +1,15 @@ # Changelog This changelog is used to track all major changes to django-apscheduler. + +## v0.7.0(2024-09-24) -## v0.6.3 (UNRELEASED) +**Enhancements** +- Drop support for Python 3.8 and Django 3.2. +- Add support for Python 3.9 to 3.12, Django 4.2 to 5.1 +- Bump pytest to >7, remove pytest-pythonpath as it is no longer needed. +- Add tox.ini file to run tests against all supported versions of Python and Django. +- Update CI configuration to use tox. **Fixes** From 842fd58031665717f0e2b1402b2c6259e3589694 Mon Sep 17 00:00:00 2001 From: tgoddessana Date: Wed, 25 Sep 2024 20:07:02 +0900 Subject: [PATCH 15/15] docs: update README.md --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index efc4a21..9cfa100 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,3 @@ -## WARNING: This project is no longer actively maintained. - -It has been a few years since I have worked on any Django applications in production, and I am not making use of this -codebase myself anymore. - -We have an [issue open](https://github.com/jcass77/django-apscheduler/issues/190) to look for a new maintainer. Please -comment there if you are interested in becoming involved. - Django APScheduler ==================