From 7443f2f36ca5a4bb72056145d65f688ecb017d0f Mon Sep 17 00:00:00 2001 From: Josh Harwood Date: Mon, 22 Jul 2019 10:08:20 +0100 Subject: [PATCH 01/10] feat(StateLog): Migrated state log from integerfield to charfield --- django_fsm_log/__init__.py | 1 + django_fsm_log/checks.py | 71 +++++++++++++++++++ .../migrations/0006_allow_non_numeric_ids.py | 18 +++++ django_fsm_log/models.py | 2 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 django_fsm_log/checks.py create mode 100644 django_fsm_log/migrations/0006_allow_non_numeric_ids.py diff --git a/django_fsm_log/__init__.py b/django_fsm_log/__init__.py index 16c2564..4170e72 100644 --- a/django_fsm_log/__init__.py +++ b/django_fsm_log/__init__.py @@ -1 +1,2 @@ default_app_config = 'django_fsm_log.apps.DjangoFSMLogAppConfig' +from .checks import * # noqa diff --git a/django_fsm_log/checks.py b/django_fsm_log/checks.py new file mode 100644 index 0000000..a9cc467 --- /dev/null +++ b/django_fsm_log/checks.py @@ -0,0 +1,71 @@ +import ast +import inspect + +import django +from django.core.checks import ( + Warning, + register, + Tags, +) +from django.core.exceptions import FieldDoesNotExist + +from django_fsm_log.models import StateLog + + +@register(Tags.compatibility) +def integer_object_id_check(app_configs, **kwargs): + errors = [] + for app in django.apps.apps.get_app_configs(): + + # Skip third party apps. + if app.path.find('site-packages') > -1: + continue + + for model in app.get_models(): + for check_message in check_model_for_integer_object_id(model): + errors.append(check_message) + return errors + + +def check_model_for_integer_object_id(model): + """Check a single model. + + Yields (django.checks.CheckMessage) + """ + model_source = inspect.getsource(model) + model_node = ast.parse(model_source) + + for node in model_node.body[0].body: + + # Check if node is a model field. + if not isinstance(node, ast.Assign): + continue + + if len(node.targets) != 1: + continue + + if not isinstance(node.targets[0], ast.Name): + continue + + field_name = node.targets[0].id + try: + field = model._meta.get_field(field_name) + except FieldDoesNotExist: + continue + + # Node is a model field here + + # Check if field has foreign key to StateLog defined + for kw in node.value.keywords: + if kw.arg == 'to': + to = kw + if to == 'django_fsm_log.StateLog' or isinstance(to, StateLog): + yield Warning( + 'StateLog has changed its object_id from PositiveIntegerField to TextField to better support ' + 'the primary key types in Django.', + hint='Migration PositiveIntegerField -> TextField is potentially needed on field {}.'.format( + field.name + ), + obj=field, + id='django_fsm_log.W001', + ) diff --git a/django_fsm_log/migrations/0006_allow_non_numeric_ids.py b/django_fsm_log/migrations/0006_allow_non_numeric_ids.py new file mode 100644 index 0000000..261f3bf --- /dev/null +++ b/django_fsm_log/migrations/0006_allow_non_numeric_ids.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.3 on 2018-11-16 12:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_fsm_log', '0005_description_null'), + ] + + operations = [ + migrations.AlterField( + model_name='statelog', + name='object_id', + field=models.TextField(db_index=True), + ), + ] diff --git a/django_fsm_log/models.py b/django_fsm_log/models.py index 0f31a3b..133f93e 100644 --- a/django_fsm_log/models.py +++ b/django_fsm_log/models.py @@ -23,7 +23,7 @@ class StateLog(models.Model): transition = models.CharField(max_length=255) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) - object_id = models.PositiveIntegerField(db_index=True) + object_id = models.TextField(db_index=True) content_object = GenericForeignKey('content_type', 'object_id') description = models.TextField(blank=True, null=True) From 584639aa27c7f495862373053dc4756c3865db70 Mon Sep 17 00:00:00 2001 From: Josh Harwood Date: Mon, 22 Jul 2019 10:54:19 +0100 Subject: [PATCH 02/10] fix(checks): Imported StateLog too early for the tests --- django_fsm_log/checks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django_fsm_log/checks.py b/django_fsm_log/checks.py index a9cc467..147253e 100644 --- a/django_fsm_log/checks.py +++ b/django_fsm_log/checks.py @@ -9,8 +9,6 @@ ) from django.core.exceptions import FieldDoesNotExist -from django_fsm_log.models import StateLog - @register(Tags.compatibility) def integer_object_id_check(app_configs, **kwargs): @@ -32,6 +30,9 @@ def check_model_for_integer_object_id(model): Yields (django.checks.CheckMessage) """ + + from django_fsm_log.models import StateLog + model_source = inspect.getsource(model) model_node = ast.parse(model_source) From b2314b7853cd2565d4ac97f8f4cedb422b31a36e Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:13:23 +0500 Subject: [PATCH 03/10] python3 only --- .travis.yml | 10 ---------- tox.ini | 9 ++++----- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb46672..61b2b8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,16 +2,6 @@ language: python matrix: include: - - env: TOXENV=py27-dj-1.8 - python: 2.7 - - env: TOXENV=py27-dj-1.11 - python: 2.7 - - env: TOXENV=py34-dj-1.8 - python: 3.4 - - env: TOXENV=py34-dj-1.11 - python: 3.4 - - env: TOXENV=py35-dj-1.8 - python: 3.5 - env: TOXENV=py35-dj-1.11 python: 3.5 - env: TOXENV=py36-dj-1.8 diff --git a/tox.ini b/tox.ini index 10d4a7e..cb055c0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist = - py{27,34,35,36}-dj-{1.8,1.11} - py{34,35,36}-dj-2.0 - py{35,36}-dj-master + py{35,36,37}-dj-{1.11} + py{35,36,37}-dj-2.0 + py{35,36,37}-dj-master flake8 [testenv] @@ -10,14 +10,13 @@ usedevelop = true commands = pytest --cov=django_fsm_log --cov=tests {posargs} extras = testing deps = - dj-1.8: Django>=1.8,<1.9 dj-1.11: Django>=1.11,<2.0 dj-2.0: Django>=2.0,<2.1 dj-2.1: Django>=2.1,<2.2 dj-master: https://github.com/django/django/archive/master.tar.gz [testenv:flake8] -basepython = python3.6 +basepython = python3.7 commands = flake8 django_fsm_log tests extras = deps = From 4682939519cd2a0e6c9145b83677c71f467427a0 Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:17:43 +0500 Subject: [PATCH 04/10] travis tox update --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index cb055c0..de815e9 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,8 @@ deps = dj-1.11: Django>=1.11,<2.0 dj-2.0: Django>=2.0,<2.1 dj-2.1: Django>=2.1,<2.2 + dj-2.2: Django>=2.2,<2.3 + dj-3.0: Django>=3.0,<4.0 dj-master: https://github.com/django/django/archive/master.tar.gz [testenv:flake8] From 9da562ac42c775e24c1bafd87e127079f51612a9 Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:25:38 +0500 Subject: [PATCH 05/10] travis tox update --- .travis.yml | 20 +++++++++++++------- tox.ini | 5 +++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 61b2b8b..5f8534d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,25 +4,31 @@ matrix: include: - env: TOXENV=py35-dj-1.11 python: 3.5 - - env: TOXENV=py36-dj-1.8 + - env: TOXENV=py35-dj-1.11 python: 3.6 - env: TOXENV=py36-dj-1.11 - python: 3.6 - - env: TOXENV=py34-dj-2.0 - python: 3.4 + python: 3.7 - env: TOXENV=py35-dj-2.0 python: 3.5 - env: TOXENV=py36-dj-2.0 python: 3.6 - env: TOXENV=py36-dj-2.1 python: 3.6 - - env: TOXENV=py36-dj-master + - env: TOXENV=py36-dj-2.2 python: 3.6 + - env: TOXENV=py37-dj-3.0 + python: 3.7 + - env: TOXENV=py38-dj-3.0 + python: 3.8 + - env: TOXENV=py37-dj-master + python: 3.7 + - env: TOXENV=py38-dj-master + python: 3.8 - env: TOXENV=flake8 - python: 3.6 + python: 3.8 allow_failures: - env: TOXENV=py36-dj-master - python: 3.6 + python: 3.8 install: - pip install tox codecov diff --git a/tox.ini b/tox.ini index de815e9..bb10ea4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,9 @@ [tox] envlist = py{35,36,37}-dj-{1.11} - py{35,36,37}-dj-2.0 - py{35,36,37}-dj-master + py{35,36,37}-dj-{2.0,2.1,2.2} + py{37,38}-dj-{3.0} + py{37,38}-dj-{master} flake8 [testenv] From ad05c5743930c00f6fd35d7f5e20710a82b424fa Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:32:20 +0500 Subject: [PATCH 06/10] fix python2 models --- django_fsm_log/models.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/django_fsm_log/models.py b/django_fsm_log/models.py index 133f93e..646d06c 100644 --- a/django_fsm_log/models.py +++ b/django_fsm_log/models.py @@ -1,10 +1,7 @@ -# -*- coding:utf-8 -*- -from __future__ import unicode_literals - from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.db import models -from django.utils.encoding import force_text, python_2_unicode_compatible +from django.utils.encoding import force_text from django.utils.timezone import now from django_fsm import FSMFieldMixin, FSMIntegerField @@ -12,7 +9,6 @@ from .managers import StateLogManager -@python_2_unicode_compatible class StateLog(models.Model): timestamp = models.DateTimeField(default=now) by = models.ForeignKey(getattr(settings, 'AUTH_USER_MODEL', 'auth.User'), blank=True, From e446381fa304deecee91e0be60f60c8ee8475fa7 Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:34:49 +0500 Subject: [PATCH 07/10] travis fix --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f8534d..9878d8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ matrix: include: - env: TOXENV=py35-dj-1.11 python: 3.5 - - env: TOXENV=py35-dj-1.11 - python: 3.6 - env: TOXENV=py36-dj-1.11 + python: 3.6 + - env: TOXENV=py37-dj-1.11 python: 3.7 - env: TOXENV=py35-dj-2.0 python: 3.5 From 74bdb464b6a5e3b1fd9175584aad0971b328014b Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:44:13 +0500 Subject: [PATCH 08/10] tox fix --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bb10ea4..6e4324c 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ deps = dj-master: https://github.com/django/django/archive/master.tar.gz [testenv:flake8] -basepython = python3.7 +basepython = python3.8 commands = flake8 django_fsm_log tests extras = deps = From d614849f1ae374200594497f9917453c3dffd1a8 Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 00:58:39 +0500 Subject: [PATCH 09/10] fix flake --- django_fsm_log/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django_fsm_log/conf.py b/django_fsm_log/conf.py index 52af658..b11789f 100644 --- a/django_fsm_log/conf.py +++ b/django_fsm_log/conf.py @@ -1,4 +1,3 @@ -from django.conf import settings # noqa:F811 from appconf import AppConf From 843366cb7496e7c35a70d47872b90fa20a1b6a2b Mon Sep 17 00:00:00 2001 From: kcrebound Date: Tue, 2 Jun 2020 01:04:57 +0500 Subject: [PATCH 10/10] fix flake --- django_fsm_log/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django_fsm_log/conf.py b/django_fsm_log/conf.py index b11789f..28959ca 100644 --- a/django_fsm_log/conf.py +++ b/django_fsm_log/conf.py @@ -1,3 +1,4 @@ +from django.conf import settings # noqa from appconf import AppConf