Skip to content

Commit

Permalink
Get rid of names_digest hack no longer needed (#14459)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding authored Sep 26, 2023
1 parent 159dd62 commit 770cc10
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
27 changes: 1 addition & 26 deletions awx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,14 @@ def version_file():
except ImportError: # pragma: no cover
MODE = 'production'

import hashlib

try:
import django # noqa: F401

HAS_DJANGO = True
except ImportError:
HAS_DJANGO = False
pass
else:
from django.db.backends.base import schema
from django.db.models import indexes
from django.db.backends.utils import names_digest
from django.db import connection

if HAS_DJANGO is True:
# See upgrade blocker note in requirements/README.md
try:
names_digest('foo', 'bar', 'baz', length=8)
except ValueError:

def names_digest(*args, length):
"""
Generate a 32-bit digest of a set of arguments that can be used to shorten
identifying names. Support for use in FIPS environments.
"""
h = hashlib.md5(usedforsecurity=False)
for arg in args:
h.update(arg.encode())
return h.hexdigest()[:length]

schema.names_digest = names_digest
indexes.names_digest = names_digest


def find_commands(management_dir):
# Modified version of function from django/core/management/__init__.py.
Expand Down
10 changes: 2 additions & 8 deletions requirements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ for instructions.

If operating in a FIPS environment, `hashlib.md5()` will raise a `ValueError`,
but will support the `usedforsecurity` keyword on RHEL and Centos systems.

Keep an eye on https://code.djangoproject.com/ticket/28401

The override of `names_digest` could easily be broken in a future version.
Check that the import remains the same in the desired version.

https://github.com/django/django/blob/af5ec222ccd24e81f9fec6c34836a4e503e7ccf7/django/db/backends/base/schema.py#L7
This used to be a problem with `names_digest` function in Django, but
was fixed upstream in Django 4.1.

### django-split-settings

Expand Down Expand Up @@ -172,4 +167,3 @@ available on PyPi with source distribution.

Version 4.8 makes us a little bit nervous with changes to `searchwindowsize` https://github.com/pexpect/pexpect/pull/579/files
Pin to `pexpect==4.7.x` until we have more time to move to `4.8` and test.

0 comments on commit 770cc10

Please sign in to comment.