Skip to content

3.15 missing package inflection #9291

New issue

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

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

Already on GitHub? # to your account

Closed
robd003 opened this issue Mar 17, 2024 · 3 comments · Fixed by #9303
Closed

3.15 missing package inflection #9291

robd003 opened this issue Mar 17, 2024 · 3 comments · Fixed by #9303

Comments

@robd003
Copy link

robd003 commented Mar 17, 2024

New issue in the 3.15 release where if you use generateschema and have a list in your output you will get a ModuleNotFound error.

 > [19/21] RUN poetry run python manage.py generateschema --file /code/templates/openapi-schema.yml:                                                                                                                                                                                                                                                                   
2.585 Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                                                                                 
2.586   File "/code/manage.py", line 22, in <module>                                                                                                                                                                                                                                                                                                                                                                                     
2.587     main()                                                                                                                                                                                                                                                                                                                                                                                                                         
2.588   File "/code/manage.py", line 18, in main                                                                                                                                                                                                                                                                                                                                                                                         
2.589     execute_from_command_line(sys.argv)
2.590   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
2.590     utility.execute()
2.591   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
2.592     self.fetch_command(subcommand).run_from_argv(self.argv)
2.593   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/django/core/management/base.py", line 412, in run_from_argv
2.593     self.execute(*args, **cmd_options)
2.594   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/django/core/management/base.py", line 458, in execute
2.595     output = self.handle(*args, **options)
2.596              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.600   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/rest_framework/management/commands/generateschema.py", line 43, in handle
2.601     schema = generator.get_schema(request=None, public=True)
2.602              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.606   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/rest_framework/schemas/openapi.py", line 80, in get_schema
2.608     operation = view.schema.get_operation(path, method)
2.608                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.608   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/rest_framework/schemas/openapi.py", line 146, in get_operation
2.608     operation['operationId'] = self.get_operation_id(path, method)
2.608                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.608   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/rest_framework/schemas/openapi.py", line 268, in get_operation_id
2.608     name = self.get_operation_id_base(path, method, action)
2.608            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.608   File "/root/.cache/pypoetry/virtualenvs/allfactors-django-MATOk_fk-py3.12/lib/python3.12/site-packages/rest_framework/schemas/openapi.py", line 250, in get_operation_id_base
2.608     from inflection import pluralize
2.608 ModuleNotFoundError: No module named 'inflection'
@tomchristie
Copy link
Member

Ah yep, needs resolving.

Introduced by PR #8017.

Ooptions...

  • Revert the PR. (Marginally incorrect naming is better than broken behavior)
  • Add the dependency

@robd003
Copy link
Author

robd003 commented Mar 18, 2024

I vote for including the dependency

One other idea:

try:
    from inflection import pluralize
except ImportError:
    def pluralize(input):
        if not input.endswith('s'):
            input += "s"

browniebroke added a commit to browniebroke/django-rest-framework that referenced this issue Mar 18, 2024
tfranzel added a commit that referenced this issue Mar 18, 2024
* Make inflection package truly optional

Fix #9291

* Make inflection compat layer consistent with the others

Co-authored-by: T. Franzel <13507857+tfranzel@users.noreply.github.com>

---------

Co-authored-by: T. Franzel <13507857+tfranzel@users.noreply.github.com>
@tfranzel
Copy link
Member

tfranzel commented Mar 18, 2024

I took the liberty to opt for a third option, i.e handling it analog to uritemplate. That is another optional package that needs to be installed for using the built-in generator. Both packages are listed as optional, but need to be explicitly installed for schema generation. This will still fail, but with a better error message.

We updated the docs to reflect that requirement though.

@robd003 Also note that the built-in schema generator is deprecated. I would recommend to use one of the 3rd party alternatives instead.

Imho the proper way would be to introduce djangorestframework[openapi], but seems like overkill given that all this is deprecated anyway.

Archaeopteryx added a commit to Archaeopteryx/treeherder that referenced this issue Apr 3, 2024
The API documentation page was broken: encode/django-rest-framework#9291

Revert "Bump djangorestframework from 3.15.0 to 3.15.1"

This reverts commit 995ce03.

Revert "Bump djangorestframework from 3.14.0 to 3.15.0"

This reverts commit 9b9a11f.
Archaeopteryx added a commit to mozilla/treeherder that referenced this issue Apr 9, 2024
The API documentation page was broken: encode/django-rest-framework#9291

Revert "Bump djangorestframework from 3.15.0 to 3.15.1"

This reverts commit 995ce03.

Revert "Bump djangorestframework from 3.14.0 to 3.15.0"

This reverts commit 9b9a11f.
Archaeopteryx added a commit to Archaeopteryx/treeherder that referenced this issue Apr 26, 2024
The API documentation page was broken: encode/django-rest-framework#9291

Revert "Bump djangorestframework from 3.15.0 to 3.15.1"

This reverts commit 995ce03.

Revert "Bump djangorestframework from 3.14.0 to 3.15.0"

This reverts commit 9b9a11f.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants