diff --git a/ietf/checks.py b/ietf/checks.py index 7cd8402f8..118375317 100644 --- a/ietf/checks.py +++ b/ietf/checks.py @@ -351,10 +351,21 @@ def check_svn_import(app_configs, **kwargs): return errors @checks.register('files') -def maybe_patch_django_db_model_fields_unicode_comparison(app_configs, **kwargs): +def maybe_patch_django(app_configs, **kwargs): errors = [] - for patch_file in settings.CHECKS_PATCHES_TO_APPLY: - patch_set = patch.fromfile(patch_file) + # Change path to our copy of django (this assumes we're running in a + # virtualenv, which we should) + import os, django + django_path = os.path.dirname(django.__file__) + parent_path = os.path.dirname(django_path) + saved_cwd = os.getcwd() + os.chdir(parent_path) + # All patches in settings.CHECKS_DJANGO_PATCHES_TO_APPLY must have a + # relative file path rooted in the django dir, for instance + # 'django/db/models/fields/__init__.py' + for patch_file in settings.CHECKS_DJANGO_PATCHES_TO_APPLY: + patch_path = os.path.join(saved_cwd, patch_file) + patch_set = patch.fromfile(patch_path) if patch_set: if not patch_set.apply(): errors.append(checks.Warning( @@ -368,6 +379,7 @@ def maybe_patch_django_db_model_fields_unicode_comparison(app_configs, **kwargs) hint="Make sure that the patch file contains a unified diff", id="datatracker.W0001", )) + os.chdir(saved_cwd) return errors @checks.register('security') diff --git a/ietf/settings.py b/ietf/settings.py index f1b3dcf5e..b3706abb9 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -927,7 +927,7 @@ SILENCED_SYSTEM_CHECKS = [ "fields.W342", # Setting unique=True on a ForeignKey has the same effect as using a OneToOneField. ] -CHECKS_PATCHES_TO_APPLY = [ +CHECKS_DJANGO_PATCHES_TO_APPLY = [ 'patch/fix-django-unicode-comparison-bug.patch', ] diff --git a/patch/fix-django-unicode-comparison-bug.patch b/patch/fix-django-unicode-comparison-bug.patch index 800f99b58..32ee103d5 100644 --- a/patch/fix-django-unicode-comparison-bug.patch +++ b/patch/fix-django-unicode-comparison-bug.patch @@ -1,5 +1,5 @@ ---- ./../yang/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py 2017-06-14 08:43:21.665812000 -0700 -+++ env/lib/python2.7/site-packages/django/db/models/fields/__init__.py 2017-12-17 14:34:03.023976702 -0800 +--- django/db/models/fields/__init__.py.old 2017-06-14 08:43:21.665812000 -0700 ++++ django/db/models/fields/__init__.py 2017-12-17 14:34:03.023976702 -0800 @@ -2323,7 +2323,7 @@ if self.has_default() and not callable(self.default): return self.default