From 8b646df9fef9987d5e77381eeeaeae69d94702da Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 23 Dec 2021 11:53:46 +0000 Subject: [PATCH 1/2] Fix the empty content type on migration issues --- .../migrations/0008_url_manager_data_migration.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/djangocms_url_manager/migrations/0008_url_manager_data_migration.py b/djangocms_url_manager/migrations/0008_url_manager_data_migration.py index 46244f4..14a25b7 100644 --- a/djangocms_url_manager/migrations/0008_url_manager_data_migration.py +++ b/djangocms_url_manager/migrations/0008_url_manager_data_migration.py @@ -22,7 +22,16 @@ def forwards(apps, schema_editor): UrlGrouper = apps.get_model("djangocms_url_manager", "UrlGrouper") User = apps.get_model('auth', 'User') - url_contenttype = ContentType.objects.get(app_label='djangocms_url_manager', model='url') + # The test suite fails to find the Content type, in this scenario we + # try and find the content type and create it if it doesn't yet exist using + # ContentType.objects.get_for_model + # This is the safest way because the following has been heavily manually tested already: + # ContentType.objects.get(app_label='djangocms_url_manager', model='url') + try: + url_contenttype = ContentType.objects.get(app_label='djangocms_url_manager', model='url') + except ContentType.DoesNotExist: + url_contenttype = ContentType.objects.get_for_model(Url) + url_queryset = Url.objects.all() if djangocms_versioning_config_enabled and djangocms_versioning_installed: From f17df1aebc56b63371a6a2c84eb0eaccb9823eca Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 23 Dec 2021 14:39:17 +0000 Subject: [PATCH 2/2] Handle no users set test error --- .../migrations/0008_url_manager_data_migration.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/djangocms_url_manager/migrations/0008_url_manager_data_migration.py b/djangocms_url_manager/migrations/0008_url_manager_data_migration.py index 14a25b7..e07b7c1 100644 --- a/djangocms_url_manager/migrations/0008_url_manager_data_migration.py +++ b/djangocms_url_manager/migrations/0008_url_manager_data_migration.py @@ -34,7 +34,10 @@ def forwards(apps, schema_editor): url_queryset = Url.objects.all() - if djangocms_versioning_config_enabled and djangocms_versioning_installed: + # Only set the additional user etc if + # - versioning is enabled + # - there is url data, test suites fail when empty if not + if djangocms_versioning_config_enabled and djangocms_versioning_installed and len(url_queryset): # Get a migration user. migration_user = User.objects.get(id=DJANGOCMS_URL_MANAGER_VERSIONING_MIGRATION_USER_ID) Version = apps.get_model('djangocms_versioning', 'Version')