Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On CLI invocation: TypeError: 'module' object is not iterable #157

Closed
souldeux opened this issue Sep 25, 2020 · 6 comments
Closed

On CLI invocation: TypeError: 'module' object is not iterable #157

souldeux opened this issue Sep 25, 2020 · 6 comments

Comments

@souldeux
Copy link

Describe the bug
When invoking ./manage.py spectacular --file schema.yml I encounter the following error:

Traceback (most recent call last):
  File "manage.py", line 25, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/management/commands/spectacular.py", line 50, in handle
    schema = generator.get_schema(request=None, public=True)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/generators.py", line 178, in get_schema
    paths=self.parse(request, public),
  File "/usr/lib/python3.8/site-packages/drf_spectacular/generators.py", line 150, in parse
    path = modify_for_versioning(self.inspector.patterns, method, path, view, version)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/plumbing.py", line 656, in modify_for_versioning
    urlconf=tuple(detype_pattern(p) for p in patterns)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/plumbing.py", line 656, in <genexpr>
    urlconf=tuple(detype_pattern(p) for p in patterns)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/plumbing.py", line 679, in detype_pattern
    urlconf_name=[detype_pattern(p) for p in pattern.urlconf_name],
TypeError: 'module' object is not iterable

To Reproduce
Attempting to generate a schema via the CLI or by accessing the web interface reliably reproduces this bug for me.

Things maybe worth noting:

  • I am using the drf-nested-routers package
  • This error only occurs in version 0.9.13. In version 0.9.12 I encounter a different error:
Traceback (most recent call last):
  File "manage.py", line 25, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/management/commands/spectacular.py", line 50, in handle
    schema = generator.get_schema(request=None, public=True)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/generators.py", line 166, in get_schema
    paths=self.parse(request, public),
  File "/usr/lib/python3.8/site-packages/drf_spectacular/generators.py", line 141, in parse
    path = modify_for_versioning(self.inspector.patterns, method, path, view, version)
  File "/usr/lib/python3.8/site-packages/drf_spectacular/plumbing.py", line 629, in modify_for_versioning
    mocked_request.resolver_match = get_resolver(tuple(patterns)).resolve(path)
  File "/usr/lib/python3.8/site-packages/django/urls/resolvers.py", line 575, in resolve
    raise Resolver404({'tried': tried, 'path': new_path})

Expected behavior
Successful schema generation

@tfranzel
Copy link
Owner

hi @souldeux, looks like a generic issue not bound to drf-nested-routers. 0.9.12 had a problem with namespace versioning in combination with typed (/foo/<int:bar>) urlpatterns, which detype_patterns is supposed to fix.

looks like the source of the problem is using namespace versioning in combination with module strings in includes (django.conf.urls.include('MODULE_STR')).

that should be fixed now. can you confirm that this works?

@souldeux
Copy link
Author

Thanks for giving this such quick attention! I can confirm that this now works.

@Javedgouri
Copy link

Hi ,

when we are planning for release. for this fix.

@tfranzel
Copy link
Owner

tfranzel commented Oct 4, 2020

hey, we have a few fixes on master so i think its fair to do a release. will do it later today

@tfranzel
Copy link
Owner

tfranzel commented Oct 4, 2020

@Javedgouri @souldeux 0.9.14 is live 🚀

@Javedgouri
Copy link

@tfranzel thank you for such a quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants