From 8d6f50fae8ac76514d24c2744657f4b189bb2051 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Thu, 4 May 2023 09:40:23 -0400 Subject: [PATCH] Upgrading djgno to 4.2 LTS --- awx/main/migrations/0113_v370_event_bigint.py | 23 ++++++++----------- awx/main/models/credential/__init__.py | 3 +++ .../tests/functional/models/test_inventory.py | 1 + requirements/requirements.in | 4 ++-- requirements/requirements.txt | 7 +++--- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/awx/main/migrations/0113_v370_event_bigint.py b/awx/main/migrations/0113_v370_event_bigint.py index fc85ac1708..d9f4ce1d97 100644 --- a/awx/main/migrations/0113_v370_event_bigint.py +++ b/awx/main/migrations/0113_v370_event_bigint.py @@ -12,22 +12,17 @@ def migrate_event_data(apps, schema_editor): # https://www.postgresql.org/docs/9.1/datatype-numeric.html) for tblname in ('main_jobevent', 'main_inventoryupdateevent', 'main_projectupdateevent', 'main_adhoccommandevent', 'main_systemjobevent'): with connection.cursor() as cursor: - # rename the current event table - cursor.execute(f'ALTER TABLE {tblname} RENAME TO _old_{tblname};') - # create a *new* table with the same schema - cursor.execute(f'CREATE TABLE {tblname} (LIKE _old_{tblname} INCLUDING ALL);') - # alter the *new* table so that the primary key is a big int + # This loop used to do roughly the following: + # Rename the table to _old_ + # Create a new table form the old table (it would have no rows) + # Drop the old sequnce and create a new on tied to the new table and set the sequence to the last number from the old table + # This used to work with postgres spitting out a NOTICE and DETAIL + # With the django 4.2 upgrade that changed to an ERROR and HINT + # By the time we hit the 4.2 upgrade, no one should be upgrading a database this old directly to this new schema + # So we no longer really care about having to do all of this work, we only need a table with a bigint ID field + # And this can be achieved by just changing the id column type... cursor.execute(f'ALTER TABLE {tblname} ALTER COLUMN id TYPE bigint USING id::bigint;') - # recreate counter for the new table's primary key to - # start where the *old* table left off (we have to do this because the - # counter changed from an int to a bigint) - cursor.execute(f'DROP SEQUENCE IF EXISTS "{tblname}_id_seq" CASCADE;') - cursor.execute(f'CREATE SEQUENCE "{tblname}_id_seq";') - cursor.execute(f'ALTER TABLE "{tblname}" ALTER COLUMN "id" ' f"SET DEFAULT nextval('{tblname}_id_seq');") - cursor.execute(f"SELECT setval('{tblname}_id_seq', (SELECT MAX(id) FROM _old_{tblname}), true);") - cursor.execute(f'DROP TABLE _old_{tblname};') - class FakeAlterField(migrations.AlterField): def database_forwards(self, *args): diff --git a/awx/main/models/credential/__init__.py b/awx/main/models/credential/__init__.py index f43d3f7f8d..13da3abe67 100644 --- a/awx/main/models/credential/__init__.py +++ b/awx/main/models/credential/__init__.py @@ -195,6 +195,9 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique, ResourceMixin): @cached_property def dynamic_input_fields(self): + # if the credential is not yet saved we can't access the input_sources + if not self.id: + return [] return [obj.input_field_name for obj in self.input_sources.all()] def _password_field_allows_ask(self, field): diff --git a/awx/main/tests/functional/models/test_inventory.py b/awx/main/tests/functional/models/test_inventory.py index 70b4425a06..27d2f46ec8 100644 --- a/awx/main/tests/functional/models/test_inventory.py +++ b/awx/main/tests/functional/models/test_inventory.py @@ -271,6 +271,7 @@ def test_inventory_update_excessively_long_name(inventory, inventory_source): class TestHostManager: def test_host_filter_not_smart(self, setup_ec2_gce, organization): smart_inventory = Inventory(name='smart', organization=organization, host_filter='inventory_sources__source=ec2') + smart_inventory.save() assert len(smart_inventory.hosts.all()) == 0 def test_host_distinctness(self, setup_inventory_groups, organization): diff --git a/requirements/requirements.in b/requirements/requirements.in index c7a8f62691..f6904291c0 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -10,7 +10,7 @@ cryptography>=39.0.1 ## https://github.com/ansible/awx/security/dependabot/90 Cython<3 # Since the bump to PyYAML 5.4.1 this is now a mandatory dep daphne distro -django==3.2.16 # see UPGRADE BLOCKERs https://github.com/ansible/awx/security/dependabot/67 +django==4.2 # see UPGRADE BLOCKERs django-auth-ldap django-cors-headers django-crum @@ -23,7 +23,7 @@ django-redis django-solo django-split-settings==1.0.0 # We hit a strange issue where the release process errored when upgrading past 1.0.0 see UPGRADE BLOCKERS django-taggit -djangorestframework==3.13.1 +djangorestframework djangorestframework-yaml filelock GitPython>=3.1.30 # CVE-2022-24439 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 737f052213..713372ff2c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -11,7 +11,7 @@ ansiconv==1.0.0 # via -r /awx_devel/requirements/requirements.in asciichartpy==1.5.25 # via -r /awx_devel/requirements/requirements.in -asgiref==3.5.2 +asgiref==3.6.0 # via # channels # channels-redis @@ -98,7 +98,7 @@ deprecated==1.2.13 # via jwcrypto distro==1.8.0 # via -r /awx_devel/requirements/requirements.in -django==3.2.16 +django==4.2 # via # -r /awx_devel/requirements/requirements.in # channels @@ -138,7 +138,7 @@ django-split-settings==1.0.0 # via -r /awx_devel/requirements/requirements.in django-taggit==3.1.0 # via -r /awx_devel/requirements/requirements.in -djangorestframework==3.13.1 +djangorestframework==3.14.0 # via -r /awx_devel/requirements/requirements.in djangorestframework-yaml==2.0.0 # via -r /awx_devel/requirements/requirements.in @@ -334,7 +334,6 @@ python3-openid==3.2.0 # via -r /awx_devel/requirements/requirements_git.txt pytz==2022.6 # via - # django # djangorestframework # irc # tempora