Skip to content

Commit 9fd0ce7

Browse files
dpoarchvegu
andauthored
Fix index out of range error when there are no previous versions of an object (#13)
* Fix IndexError when there are no previous versions of an object * fix workflow * fix tox.ini * remove obsolete tests * changelog * prep 1.0.2 Co-authored-by: Stefan Pratter <stefan@20c.com>
1 parent a1b242e commit 9fd0ce7

File tree

6 files changed

+32
-54
lines changed

6 files changed

+32
-54
lines changed

.github/workflows/tests.yml

+17-48
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,16 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v2
1111
- uses: actions/setup-python@v2
12-
- uses: actions/cache@v2
1312
with:
14-
path: ~/.cache/pip
15-
key: ${{ runner.os }}-pip
16-
restore-keys: ${{ runner.os }}-pip
13+
python-version: 3.9
1714
- name: Install Poetry
18-
uses: snok/install-poetry@v1.1.1
15+
uses: snok/install-poetry@v1
1916
with:
2017
virtualenvs-create: true
2118
virtualenvs-in-project: true
22-
# virtualenvs-path: ~/.venv
23-
24-
- name: Ensure cache is healthy
25-
if: steps.cache.outputs.cache-hit == 'true'
26-
shell: bash
27-
run: timeout 10s poetry run pip --version || rm -rf .venv
19+
installer-parallel: true
2820

21+
# virtualenvs-path: ~/.venv
2922
- name: Load cached venv
3023
id: cached-poetry-dependencies
3124
uses: actions/cache@v2
@@ -34,22 +27,22 @@ jobs:
3427
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
3528
# install dependencies if cache does not exist
3629
- name: Check cache and install dependencies
37-
run: poetry install
30+
run: poetry install --no-interaction --no-root
3831
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
32+
# poetry run pre-commit run --all-files
3933
- name: Run linters
4034
run: |
41-
source .venv/bin/activate
42-
# flake8 .
43-
black . --check
44-
isort .
35+
poetry run pre-commit run --all-files
36+
4537
4638
test:
47-
needs: linting
39+
# XXX needs: linting
4840
strategy:
49-
fail-fast: true
41+
fail-fast: false
5042
matrix:
5143
os: [ "ubuntu-latest", "macos-latest" ]
52-
python-version: [ "3.6", "3.7", "3.8", "3.9" ]
44+
python-version: [ "3.7", "3.8", "3.9" ]
45+
#django-version: [ "django>=2.2,<3", "django>=3.1,<4" ]
5346
runs-on: ${{ matrix.os }}
5447
steps:
5548
- name: Check out repository
@@ -58,36 +51,12 @@ jobs:
5851
uses: actions/setup-python@v2
5952
with:
6053
python-version: ${{ matrix.python-version }}
61-
- name: Install Poetry
62-
uses: snok/install-poetry@v1.1.1
63-
with:
64-
virtualenvs-create: true
65-
virtualenvs-in-project: true
66-
- name: Load cached venv
67-
id: cached-poetry-dependencies
68-
uses: actions/cache@v2
69-
with:
70-
path: .venv
71-
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
72-
# install dependencies if cache does not exist
73-
- name: Check cache and install dependencies
74-
run: poetry install
75-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
76-
- name: Run tests
54+
- name: Install dependencies
7755
run: |
78-
source .venv/bin/activate
79-
pip install tox-gh-actions
80-
tox
81-
coverage report
82-
# upload coverage stats
83-
- name: Upload coverage
84-
uses: codecov/codecov-action@v1
85-
with:
86-
file: ./coverage.xml
87-
fail_ci_if_error: true
88-
89-
90-
# upload coverage stats
56+
python -m pip install --upgrade pip
57+
pip install tox tox-gh-actions
58+
- name: Run tests
59+
run: tox
9160
- name: Upload coverage
9261
uses: codecov/codecov-action@v1
9362
with:

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ repos:
3131
hooks:
3232
- id: system
3333
name: flake8
34-
entry: poetry run flake8 .
34+
entry: poetry run flake8 src
3535
language: system
3636
pass_filenames: false

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
## Unreleased
55

66

7+
## 1.0.2
8+
### Fixed
9+
- fix list index of range issue in version admin
10+
11+
712
## 1.0.1
813
### Fixed
914
- performance issues in admin version history view

CHANGELOG.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ Unreleased:
3636
1.0.1:
3737
fixed:
3838
- performance issues in admin version history view
39+
1.0.2:
40+
fixed:
41+
- fix list index of range issue in version admin

src/django_handleref/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def history(self, history_qset):
173173

174174
versions.reverse()
175175

176+
# If there are no previous versions, return an empty history
177+
if not versions:
178+
return history
176179
previous = self.version_cls(versions[0]).previous
177180

178181
for _version in versions:

tox.ini

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

22
[tox]
33
envlist =
4-
py{36,37,38,39}-django{22,30,31,32}-reversion{2,3,4}
4+
py{37,38,39}-django{22,32}-reversion{3,4}
55
isolated_build = true
66

77
[gh-actions]
88
python =
9-
3.6: py36
109
3.7: py37
1110
3.8: py38
1211
3.9: py39
@@ -15,12 +14,11 @@ python =
1514
setenv =
1615
PYTHONDONTWRITEBYTECODE=1
1716
PYTHONWARNINGS=once
17+
extras = dev
1818
deps =
19+
poetry
1920
django22: Django>=2.2,<2.3
20-
django30: Django>=3.0,<3.1
21-
django31: Django>=3.1,<3.2
2221
django32: Django>=3.2,<3.3
23-
reversion2: django-reversion>=2<3
2422
reversion3: django-reversion>=3<4
2523
reversion4: django-reversion>=4<5
2624
whitelist_externals = poetry

0 commit comments

Comments
 (0)