Skip to content

Commit

Permalink
Added a patch for django issue #28772, a check action to apply the pa…
Browse files Browse the repository at this point in the history
…tch, and a setting that lists patches to be applied.

 - Legacy-Id: 14474
  • Loading branch information
levkowetz committed Dec 30, 2017
1 parent 9e82bb3 commit bb92c0a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
32 changes: 27 additions & 5 deletions ietf/checks.py
@@ -1,4 +1,5 @@
import os
import patch
import sys
import time
from textwrap import dedent
Expand Down Expand Up @@ -155,7 +156,7 @@ def check_yang_model_directories(app_configs, **kwargs):
" %s = %s" % (s, p),
hint = ("Please either update your local settings to point at the correct\n"
"\tdirectory, or if the setting is correct, create the indicated directory.\n"),
id = "datatracker.E0006",
id = "datatracker.E0017",
))
return errors

Expand Down Expand Up @@ -285,6 +286,7 @@ def cache_error(msg, errnum):
if not cache.get(key) == val:
errors.append(cache_error("Cache didn't accept session cookie age", "E0016"))
return errors


def maybe_create_svn_symlinks(settings):
site_packages_dir = None
Expand All @@ -307,7 +309,7 @@ def maybe_create_svn_symlinks(settings):
" %s\n" % path,
hint = "Please provide the correct python system site-package paths for\n"
"\tsvn and libsvn in SVN_PACKAGES.\n",
id = "datatracker.E0015",))
id = "datatracker.E0018",))
return errors

@checks.register('cache')
Expand Down Expand Up @@ -344,10 +346,30 @@ def check_svn_import(app_configs, **kwargs):
available at https://trac.edgewall.org/wiki/TracSubversion.
""").replace('\n', '\n ').rstrip(),
id = "datatracker.E0014",
id = "datatracker.E0019",
))
return errors

@checks.register('files')
def maybe_patch_django_db_model_fields_unicode_comparison(app_configs, **kwargs):
errors = []
for patch_file in settings.CHECKS_PATCHES_TO_APPLY:
patch_set = patch.fromfile(patch_file)
if patch_set:
if not patch_set.apply():
errors.append(checks.Warning(
"Could not apply patch from file '%s'"%patch_file,
hint="Make sure that the patch file contains a unified diff and has valid file paths",
id="datatracker.W0002",
))
else:
errors.append(checks.Warning(
"Could not parse patch file '%s'"%patch_file,
hint="Make sure that the patch file contains a unified diff",
id="datatracker.W0001",
))
return errors

@checks.register('security')
def check_api_key_in_local_settings(app_configs, **kwargs):
errors = []
Expand All @@ -366,7 +388,7 @@ def check_api_key_in_local_settings(app_configs, **kwargs):
extract the public key with 'openssl rsa -in apikey.pem -pubout > apikey.pub'.
""").replace('\n', '\n ').rstrip(),
id = "datatracker.E0015",
id = "datatracker.E0020",
))
elif not ( settings_local.API_PUBLIC_KEY_PEM == settings.API_PUBLIC_KEY_PEM
and settings_local.API_PRIVATE_KEY_PEM == settings.API_PRIVATE_KEY_PEM ):
Expand All @@ -379,7 +401,7 @@ def check_api_key_in_local_settings(app_configs, **kwargs):
Please check if you have multiple settings_local.py files.
""").replace('\n', '\n ').rstrip(),
id = "datatracker.E0016",
id = "datatracker.E0021",
))

return errors
Expand Down
4 changes: 4 additions & 0 deletions ietf/settings.py
Expand Up @@ -927,6 +927,10 @@ def skip_unreadable_post(record):
"fields.W342", # Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
]

CHECKS_PATCHES_TO_APPLY = [
'patch/fix-django-unicode-comparison-bug.patch',
]

STATS_NAMES_LIMIT = 25

UTILS_TEST_RANDOM_STATE_FILE = '.factoryboy_random_state'
Expand Down
11 changes: 11 additions & 0 deletions patch/fix-django-unicode-comparison-bug.patch
@@ -0,0 +1,11 @@
--- ./../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
@@ -2323,7 +2323,7 @@
if self.has_default() and not callable(self.default):
return self.default
default = super(BinaryField, self).get_default()
- if default == '':
+ if isinstance(default, six.text_type) and default == '':
return b''
return default

0 comments on commit bb92c0a

Please sign in to comment.