From c3c1ac062cf0455acf3e334cdcd515aa8b2ce966 Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Mon, 15 Apr 2024 15:17:59 +0500 Subject: [PATCH] fix!: router error due to already existed basename Exception in thread django-main-thread: 2024-04-15 14:56:18 Traceback (most recent call last): 2024-04-15 14:56:18 File "/opt/pyenv/versions/3.12.2/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 2024-04-15 14:56:18 self.run() 2024-04-15 14:56:18 File "/opt/pyenv/versions/3.12.2/lib/python3.12/threading.py", line 1010, in run 2024-04-15 14:56:18 self._target(*self._args, **self._kwargs) 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/utils/autoreload.py", line 64, in wrapper 2024-04-15 14:56:18 fn(*args, **kwargs) 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run 2024-04-15 14:56:18 self.check(display_num_errors=True) 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/core/management/base.py", line 419, in check 2024-04-15 14:56:18 all_issues = checks.run_checks( 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/core/checks/registry.py", line 76, in run_checks 2024-04-15 14:56:18 new_errors = check(app_configs=app_configs, databases=databases) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/core/checks/urls.py", line 13, in check_url_config 2024-04-15 14:56:18 return check_resolver(resolver) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/core/checks/urls.py", line 23, in check_resolver 2024-04-15 14:56:18 return check_method() 2024-04-15 14:56:18 ^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/urls/resolvers.py", line 416, in check 2024-04-15 14:56:18 for pattern in self.url_patterns: 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/utils/functional.py", line 48, in __get__ 2024-04-15 14:56:18 res = instance.__dict__[self.name] = self.func(instance) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/urls/resolvers.py", line 602, in url_patterns 2024-04-15 14:56:18 patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/utils/functional.py", line 48, in __get__ 2024-04-15 14:56:18 res = instance.__dict__[self.name] = self.func(instance) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/urls/resolvers.py", line 595, in urlconf_module 2024-04-15 14:56:18 return import_module(self.urlconf_name) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/opt/pyenv/versions/3.12.2/lib/python3.12/importlib/__init__.py", line 90, in import_module 2024-04-15 14:56:18 return _bootstrap._gcd_import(name[level:], package, level) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "", line 1387, in _gcd_import 2024-04-15 14:56:18 File "", line 1360, in _find_and_load 2024-04-15 14:56:18 File "", line 1331, in _find_and_load_unlocked 2024-04-15 14:56:18 File "", line 935, in _load_unlocked 2024-04-15 14:56:18 File "", line 995, in exec_module 2024-04-15 14:56:18 File "", line 488, in _call_with_frames_removed 2024-04-15 14:56:18 File "/openedx/ecommerce/ecommerce/urls.py", line 23, in 2024-04-15 14:56:18 from ecommerce.extensions.urls import urlpatterns as extensions_patterns 2024-04-15 14:56:18 File "/openedx/ecommerce/ecommerce/extensions/urls.py", line 11, in 2024-04-15 14:56:18 url(r'^api/', include(('ecommerce.extensions.api.urls', 'api'))), 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/urls/conf.py", line 34, in include 2024-04-15 14:56:18 urlconf_module = import_module(urlconf_module) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/opt/pyenv/versions/3.12.2/lib/python3.12/importlib/__init__.py", line 90, in import_module 2024-04-15 14:56:18 return _bootstrap._gcd_import(name[level:], package, level) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/ecommerce/ecommerce/extensions/api/urls.py", line 6, in 2024-04-15 14:56:18 url(r'^v2/', include(('ecommerce.extensions.api.v2.urls', 'v2'))), 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/django/urls/conf.py", line 34, in include 2024-04-15 14:56:18 urlconf_module = import_module(urlconf_module) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/opt/pyenv/versions/3.12.2/lib/python3.12/importlib/__init__.py", line 90, in import_module 2024-04-15 14:56:18 return _bootstrap._gcd_import(name[level:], package, level) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/ecommerce/ecommerce/extensions/api/v2/urls.py", line 175, in 2024-04-15 14:56:18 router.register(r'partners', partner_views.PartnerViewSet, basename='partner') \ 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/rest_framework_extensions/routers.py", line 57, in register 2024-04-15 14:56:18 self._register(*args, **kwargs) 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/rest_framework_extensions/routers.py", line 54, in _register 2024-04-15 14:56:18 return super().register(*args, **kwargs) 2024-04-15 14:56:18 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-04-15 14:56:18 File "/openedx/venv/lib/python3.12/site-packages/rest_framework/routers.py", line 59, in register 2024-04-15 14:56:18 raise ImproperlyConfigured(msg) 2024-04-15 14:56:18 django.core.exceptions.ImproperlyConfigured: Router with basename "partner" is already registered. Please provide a unique basename for viewset "" --- ecommerce/extensions/api/v2/urls.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ecommerce/extensions/api/v2/urls.py b/ecommerce/extensions/api/v2/urls.py index 36e6d0c98a5..cffc414f420 100644 --- a/ecommerce/extensions/api/v2/urls.py +++ b/ecommerce/extensions/api/v2/urls.py @@ -160,15 +160,19 @@ order_views.ManualCourseEnrollmentOrderViewSet, basename='manual-course-enrollment-order' ) -router.register(r'partners', partner_views.PartnerViewSet) \ - .register(r'catalogs', catalog_views.CatalogViewSet, - basename='partner-catalogs', parents_query_lookups=['partner_id']) -router.register(r'partners', partner_views.PartnerViewSet) \ - .register(r'products', product_views.ProductViewSet, - basename='partner-product', parents_query_lookups=['stockrecords__partner_id']) +partner_router = SimpleRouter() +partner_router.register(r'partners', partner_views.PartnerViewSet, basename='partner') +catalog_router = SimpleRouter() +catalog_router.register(r'catalogs', catalog_views.CatalogViewSet, basename='partner-catalogs') +product_router = SimpleRouter() +product_router.register(r'products', product_views.ProductViewSet, basename='partner-product') +partner_router.registry.extend(catalog_router.registry) +partner_router.registry.extend(product_router.registry) + router.register(r'products', product_views.ProductViewSet, basename='product') router.register(r'vouchers', voucher_views.VoucherViewSet, basename='vouchers') router.register(r'stockrecords', stockrecords_views.StockRecordViewSet, basename='stockrecords') urlpatterns += router.urls +urlpatterns += partner_router.urls urlpatterns = format_suffix_patterns(urlpatterns)